in reply to Swapping keys and values in a hash with slices

But nobody promised you that keys and values would return in the same order though ;-)

use Data::Dump qw( dump ); my %hash = ( 1 => "Piker", 2 => "Vin", 3 => "Sang" ); my %revhash; $revhash{$hash{$_}} = $_ for (keys(%hash)); print dump( \%hash ), "\n"; print dump( \%revhash ), "\n";
Update:

Forget about this, just use reverse as tomhukins said below.

Replies are listed 'Best First'.
Re^2: Swapping keys and values in a hash with slices
by revdiablo (Prior) on Oct 20, 2004 at 17:57 UTC
    nobody promised you that keys and values would return in the same order

    Yes, they did. Read the quoted docs more carefully:

    The values are returned in an apparently random order. The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the keys or each function would produce on the same (unmodified) hash.