Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Just another Perl shrine
 
PerlMonks  

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

by NetWallah (Canon)
on Jul 29, 2004 at 13:09 UTC ( [id://378437]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How do I modify the KEYS in a hash (copy)

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://378437]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.