in reply to whats wrong reverse %x = reverse %h?

When you reverse the list you get from a hash, keys and values are exchanged. Making a hash from the reversed list, if two values are the same, only one of the previous keys will survive as a value.

Added - I get 'w2' running your first example, but get the same as you with the second. There may be some optimization with aliases going wrong. I don't see that the construction is supposed to be undefined.

After Compline,
Zaxo

  • Comment on Re: whats wrong reverse %x = reverse %h?

Replies are listed 'Best First'.
Re^2: whats wrong reverse %x = reverse %h?
by borisz (Canon) on Sep 28, 2004 at 16:47 UTC
    Thats what I expect, but none of the examples show this behavior. the expected results from the first is for %h
    { 2 => 1, b=> 'a' } or { 2 => 'c', b=> 'a' }
    but the result is
    { a => 2, b => 2}
    even more unexpeted results from perl 5.8.4 where I get
    { '' => '2' }
    Boris