Re: Truncate an array when you have a ref to it?
- From: Ted Zlatanov <tzz@xxxxxxxxxxxx>
- Date: Wed, 27 Aug 2008 16:01:01 -0500
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
.
- References:
- Truncate an array when you have a ref to it?
- From: A. Farber
- Truncate an array when you have a ref to it?
- Prev by Date: Re: Truncate an array when you have a ref to it?
- Next by Date: Re: subprocesses lifecycle
- Previous by thread: Re: Truncate an array when you have a ref to it?
- Next by thread: Perl forgets variable every other pass in loop???
- Index(es):
Relevant Pages
|