Re: Truncate an array when you have a ref to it?
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Wed, 27 Aug 2008 20:44:28 GMT
A. Farber wrote:
Hello,
I have an object representing a player:
sub new {
my $package = shift;
my $self = {
......
CHAT => [[], [], []],
};
bless($self, $package);
}
and its CHAT member holds messages
from 3 other players in an array of 3 arrays.
Then I have a method which sends those
messages over a socket to the player:
$aref = $self->{CHAT}->[0];
push @response, 'chat0=' . join '', @$aref;
$self->{CHAT}->[0] = [];
The last line truncates the sub-array
(after the messages have been sent).
I wonder if I can truncate that array by
using the $aref ? Something like $#xxxx = -1;
Yes you could do that:
$#$aref = -1;
Or:
@$aref = ();
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- 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: perl multithreading performance
- Next by Date: Re: Truncate an array when you have a ref to it?
- Previous by thread: Truncate an array when you have a ref to it?
- Next by thread: Re: Truncate an array when you have a ref to it?
- Index(es):
Relevant Pages
|