in reply to Reversing Hash

How about this straight reversal of keys and values ...

my %hash = ( '1' => 'one', '2' => 'two', '3' => 'three' ); my %new; @new{ values %hash } = keys %hash; print Dumper( \%new );

 

perl -le 'print+unpack("N",pack("B32","00000000000000000000001000111000"))'

Replies are listed 'Best First'.
Re: Re: Reversing Hash
by Hofmator (Curate) on Mar 03, 2003 at 10:42 UTC
    only, the values are anonymous arrays and not strings ... which leads to
    my %new; @new{ map {join ' ', @$_} values %hash } = keys %hash;
    and I think I like tachyon's straightforward map better than this ...

    -- Hofmator