in reply to Pass by Value does not work
Perl is MAGIC with lists!
How do you clone a LoL (List of List)? This is also called a "deep copy".
Easy:
my @xx_clone = map {[$_]}@xx;
Correction: my @xx_clone = map {[@$_]}@xx;
map is a transformation operator that operates on lists.
Here a list of references to lists (@xx) goes into the map. Then each list gets expanded via @$_, then enclosed within a new address (the [] operator) and a new list of those is passed to @xx_clone. So we have a new List of Lists! One line!
To do this in other languages like C, requires a lot of code! And if we are talking about "ragged arrays" like we have here with varying numbers of columns, even more code!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pass by Value does not work
by gwadej (Chaplain) on Feb 22, 2009 at 23:05 UTC | |
by Marshall (Canon) on Feb 23, 2009 at 00:02 UTC | |
by gwadej (Chaplain) on Feb 24, 2009 at 14:21 UTC |