in reply to How would I do an inplace edit, prepending '~foo' to every key of a hash? (was: How would I do an inplace edit, prepending)

The complete question was:
How would I do an inplace edit, prepending "~foo" to every key of a hash?

So here's a kludge I came up with, but I'd like to do it with a map.
use strict; my %hash = ( one => 'blah', two => 'echo', thr => 'aaaak', ); foreach my $key (keys %hash) { $hash{"~foo".$key} = $hash{$key}; delete $hash{$key}; } use Data::Dumper; print Dumper(\%hash);

Replies are listed 'Best First'.
Re: Re: How would I do an inplace edit, prepending
by japhy (Canon) on Feb 09, 2001 at 05:43 UTC
      You know I ++ed that japhy and then decided that it was truly evil. OTOH at least it isn't in void context, eh? This helps the unclean feeling a bit:
      $hash{"~foo$_"} = delete $hash{$_} for keys %hash;

      --
      $you = new YOU;
      honk() if $you->love(perl)