in reply to Copying an array or hash
Which gives the expected, and desired:my $original = [qw(alpha beta gamma)]; my @duplicate; for (0..$#$original) { my $temp = $original->[$_]; $temp = rand(); push @duplicate, $temp; } print "Original: $_\n" for (@$original); print "Mofified: $_\n" for (@duplicate);
Update: Just to make things a bit more clear. I can obviously see that the original question is conserned with subroutine arguments being references. I merely expanded on the code that was attached as to not complicate the situation. Bull-blown examples with subroutines had already been posted prior to my reply. So fast to --?Original: alpha Original: beta Original: gamma Mofified: 0.421875 Mofified: 0.108734130859375 Mofified: 0.69537353515625
Update: you might be also interested in this node, global $_ behavior which discusses up to some extent aliasing.
|
|---|