in reply to Re: dereferencing a double array
in thread dereferencing a double array
As i can see, now $copy is a reference that points to an array of (a new set of) references, each of which contain the same elements as the corresponding reference in @original_array. It could be written in this way though.sub foo { my $array = shift; my $copy = [map {[@$_]} @$array]; ... Changes in $copy won't affect $array ... return $copy; }
right? And is the reason that you'd copy the elements this way is that it's faster? Again, thanks a lot for your tips, Hadisub foo { my $array = shift; my @copy = map {[@$_]} @$array; ... Changes in @copy won't affect @array ... return \@copy; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: dereferencing a double array
by JavaFan (Canon) on Oct 16, 2008 at 21:22 UTC | |
by perlrocks (Acolyte) on Oct 16, 2008 at 21:31 UTC | |
by JavaFan (Canon) on Oct 16, 2008 at 22:08 UTC |