in reply to Re: map weirdness
in thread map weirdness
#!/usr/bin/perl use strict; use warnings; my @d = ([0, 1, 2], [3, 4, 5], [6, 7, 8]); my $mapkey = 1; sub show { local($") = ", "; print("[", join(", ", map({"[@$_]"} @d)), "]\n"); } my $one = [@{$d[$mapkey]}]; my $two = $d[$mapkey]; show; # Show array. Unmodified. $one->[1] = "foo"; show; # Array is still unmodified. $two->[1] = "foo"; show; # This modifies the array. __END__ [[0, 1, 2], [3, 4, 5], [6, 7, 8]] [[0, 1, 2], [3, 4, 5], [6, 7, 8]] [[0, 1, 2], [3, foo, 5], [6, 7, 8]]
|
---|