in reply to Elegantly dereferencing multiple references
my $x = {"a" => "red"}; my $y = {"b" => "green"}; my $z = {"c" => "black"}; my ($new_x, $new_y, $new_z) = &modfifyHash($x, $y, $z); # original $x is unchanged, $new_x has new value print "\$x->{a} = $x->{a}\t\$new_x->{a} = $new_x->{a}\n"; sub modfifyHash { my ($x, $y, $z) = @_; # If we don't want to modify the originals, # then make a shallow copy for each $_ = { %$_ } for $x,$y,$z; $x->{ "a" } = "circle"; $y->{ "b" } = "square"; $z->{ "c" } = "rectangle"; return($x, $y, $z) }
|
|---|