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
  • Comment on Re: How can one change the keys of a hash to an alternative set of keys?
  • Download Code

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.