Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: How do I modify the KEYS in a hash (copy)

by NetWallah (Abbot)
on Jul 29, 2004 at 17:09 UTC ( #378437=categorized answer: print w/replies, xml ) Need Help??

Q&A > hashes > How do I modify the KEYS in a hash (copy) - Answer contributed by NetWallah

Here is another way to modify KEYS in-place.

This would be efficient in the case where there were a relatively small number of keys that required modification.

Use the previous method (copy the hash) if the number of keys requiring modification is large.

my %o=(this=>33, 'th at'=>44, other=>55,'some thing'=>66,'or another'= +>77,none=>88); while (my ($k,$v)=each %o){ my $ModifiedK = $k; next unless $ModifiedK =~s/\s/_/; delete $o{$k}; #This is SAFE !! RTFM. $o{$ModifiedK}=$v; }; print qq(Mod: $_\t=>$o{$_} \n) for sort keys %o"

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[Discipulus]: in this ubuntu i'm not able to find resource monitor, graphical mount program.. just office and amazon are exposed!

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2016-12-07 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (125 votes). Check out past polls.