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

Re: How can one change the keys of a hash to an alternative set of keys?

by pme (Monsignor)
on Feb 04, 2015 at 21:52 UTC ( [id://1115575]=note: print w/replies, xml ) Need Help??


in reply to How can one change the keys of a hash to an alternative set of keys?

$input_hash_ref->{alt_key1} = $input_hash_ref->{key1}; delete $input_hash_ref->{key1}; $input_hash_ref->{alt_key2} = $input_hash_ref->{key2}; delete $input_hash_ref->{key2};
See delete

Replies are listed 'Best First'.
Re^2: How can one change the keys of a hash to an alternative set of keys?
by LanX (Saint) on Feb 04, 2015 at 22:20 UTC
    No that's too dangerous!

    If old and new key set overlap you'll get ugly bugs.

    Defensive programming!!!

    Cheers Rolf

    PS: Je suis Charlie!

      This is a special case, because for some reason the two set of keys are guaranteed to uniquely identify the data structures behind them ( they are alternative descriptions of the same data ). They are constructed in such a way, that there can be no overlap ( in fact this takes quite a bit of effort, but ultimately it is done in a foolproof way ). It depends on the circumstances which set of keys is more convenient to access the data elements.
      This is true in general. But here I gave a specific comment on a specific question.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1115575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-03-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found