Re: Truncate an array when you have a ref to it?



On Wed, 27 Aug 2008 13:34:00 -0700 (PDT) "A. Farber" <Alexander.Farber@xxxxxxxxx> wrote:

AF> $aref = $self->{CHAT}->[0];
AF> push @response, 'chat0=' . join '', @$aref;
AF> $self->{CHAT}->[0] = [];

AF> The last line truncates the sub-array
AF> (after the messages have been sent).

Actually it assigns a new value to that reference. The old array still
exists with the full contents if you have another reference to it (check
$aref, for instance).

AF> I wonder if I can truncate that array by
AF> using the $aref ? Something like $#xxxx = -1;

Sure:

@$aref = ();

or, equivalently,

@{$self->{CHAT}->[0]} = ();

Ted
.



Relevant Pages

  • Re: VB-101: Passing Arrays ByVal vs ByRef
    ... changed if an array is passed by Val. ... ' new reference ... As each function creates a new array object, ... 'secondArray' and 'secondArrayCopy'. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Need help with textboxes
    ... The JavaScript 1.5 Reference already states: ... All forms and their children are stored in an array ... use dot notation or object literals. ... No. Bracket property accessors allow their argument to be any string value. ...
    (comp.lang.javascript)
  • Re: Garbage Collection Issues in long-standing services
    ... the pinned array should get unpinned or ... The receive case is done quite well, I do create a 4K buffer and reuse it ... and remove the reference to my wrapper socket class, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to give selective access to the methods in a class?
    ... different memory locations at different times. ... The reference still leads to the ... So array resizing ... program pushes certain objects into the circular buffer, ...
    (comp.lang.java.programmer)
  • Re: Perlish map() function
    ... the reference material, the Array constructor was introduced in JavaScript ... evaluation would result in a ReferenceError. ... identifier shows that it is true. ...
    (comp.lang.javascript)