in reply to Swapping Two Hash Values

Hashes can have duplicate VALUES, but not duplicate KEYS. You assigned a value to the key of '', probably because your assignment statement's left side's key expression evaluated to undef. (Undef stringizes as ''.)

I shouldn't scan so quickly, the odd values-first printout threw me off. However, this should explain your odd "duplicate keys" mystery.

%hash = ( '1' => 'angel', '2' => 'buffy', '3' => 'cordelia', '4' => 'dawn', '5' => 'ethan' '54' => undef, '6' => 'faith', '7' => 'giles', );

The printf "%d" turned the key '5 4' into an integer '5'.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Re: Swapping Two Hash Values
by Cody Pendant (Prior) on May 28, 2003 at 00:44 UTC
    You assigned a value to the key of ''
    Huh? I'm really confused now. The key is the number, not the name. That display says the value is undef and the key is 5.
    --
    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D

      Ed got this one wrong, Cody. Listen to Zaxo.

      -sauoq
      "My two cents aren't worth a dime.";