in reply to can I change hash keys or values directly
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my %hash = (key1 => 'val1', key2 => 'val2'); s/val/V/ for values %hash; say "$_ => $hash{$_}" for keys %hash;
You can't modify the keys in this way, though (and both the facts are documented in keys and values. That's because you can't change a key in a hash, you need to remove the old one and create a new one, because the after a key change, the value is most probably going to be stored in a different place.
Using a slice is probably the best you can do.
Be sure to keep the keys unique after the modification!my @old = keys %hash; @hash{map uc, @old} = delete @hash{@old};
|
|---|