Chas. Owens wrote:
> On Wed, Jul 8, 2009 at 09:31, Steve Bertrand<st...@ibctech.ca> wrote:
> snip
>> my %newhash = map { $_ =~ s/h_/hello_/; ($_, $hash{$_}) } keys %hash;
> snip
> 
> That will still have a problem: $_ is changed, so it won't reference
> the correct thing in %hash.  Try this instead:
> 
> my %newhash = map { (my $k = $_) =~ s/h_/hello_/; $k => $hash{$_} } keys 
> %hash;
> 
> Although, at this point the map is becoming complex enough that
> 
> my %newhash;
> for my $key (keys %hash) {
>     (my $new_key = $key) =~ s/h_/hello_/;
>     $newhash{$new_key} = $hash{$key}
> }
> 
> may be more understandable.

I agree, and just before you mailed, I did figure out that I needed a
placeholder, by using your recommended 'w' command in the debugger. It's
a tiny bit different than your approach, but it works ;)

%hash = map { my $x = $_; $_ =~ s/h_/hello_/;$_, $hash{$x} } keys %hash;

Thanks,

Steve

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to