For one thing you're committing a thinko in that a hash is by definition unordered (unless you do some tie magic under the hood) so your destination is misnamed. That being said since keys and values will return things in the same order so long as you don't change the underlying hash you can swap things the obvious way.
main::(-e:1): 0 DB<1> %foo = qw( a b c d ) DB<2> @bar{ values %foo } = keys %foo DB<3> x \%bar 0 HASH(0x7fb23c8b94b8) 'b' => 'a' 'd' => 'c'
The cake is a lie.
The cake is a lie.
The cake is a lie.
In reply to Re: Is there a way to switch a hash values <> keys with a slice?
by Fletch
in thread Is there a way to switch a hash values <> keys with a slice?
by misterperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |