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.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to