in reply to Copying an array or hash
Depending on what you need to do, you can either call 'local' on the individual values, or you can just copy the whole array in one pass, so long as you don't have references in the array (or hash). You can also pass by value, rather than by reference, but only if you're passing a single array or hash (and again, it won't work w/ complex structures)
sub whatever { my $array_ref = shift; my @copy = ( @$array_ref ); @copy[1] = 'whatever'; } sub blah { my $array_ref = shift; local $array_ref->[0] = 'blah'; } sub test { my @array = @_; $array[2] = 'test'; } my $test = [ qw( 0 1 2 3 4 5 ) ]; whatever($test); blah($test); test($test); use Data::Dumper; print Dumper $test;
|
|---|