⭐ in reply to How do I modify the KEYS in a hash (copy)
The trick here is to save a copy of the Value into "$y" before "$_" is modified.my %Orig=('a b'=>44, 'c d'=>22, rr=>99); my %Copy = map {my $y=$Orig{$_}; #Save Copy of Val tr/ /_/; $_ => $y} keys %Orig; print qq(C: $_ => $Copy{$_}\n) for keys %Copy; print qq(O: $_ => $Orig{$_}\n) for keys %Orig;
|
|---|