in reply to Hash Copy Decipher???

This code does copy the values of $tsh, but it's a shallow copy. Copies of the values that are references will still point to the same place that the references in $tsh point.

You're also correct that the three pair declarations after %$tsh will overwrite any values of $tsh with those keys.

Replies are listed 'Best First'.
Re^2: Hash Copy Decipher???
by Errto (Vicar) on Apr 25, 2007 at 20:53 UTC
    I hesitate to question chromatic on such things, but is the second part of that necessarily true? Since the elements of %$tsh are interpolated into a list, what we have is a list assignment to a hash where the same key may appear more than once, and my impression was that it was undefined which of the two values would be used. OTOH, I looked in perldata just now and the only mention I could find of this topic was:
    A hash can be initialized using a literal list holding pairs of items to be interpreted as a key and a value:
    and no mention of what happens when a key is duplicated.
      I hesitate to question chromatic on such things, but is the second part of that necessarily true?

      Hash keys don't have (easily identifiable) order, but lists certainly do.

      There's no requirement that a tied hash do anything specific when overwriting an existing key, but if Perl suddenly changes the order of operations when processing lists, you'll know it.