in reply to Is there a way to switch a hash values <> keys with a slice?

reverse is your friend, but hashes have no order so your sort is for vain. .

main::(-e:1): 0 DB<1> @h{ a..c } = 1..3 DB<2> x \%h 0 HASH(0x33c38e0) 'a' => 1 'b' => 2 'c' => 3 DB<3> %h2 = reverse %h DB<4> x \%h2 0 HASH(0x3554090) 1 => 'a' 2 => 'b' 3 => 'c' DB<5>

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Is there a way to switch a hash values <> keys with a slice?
by misterperl (Friar) on Apr 19, 2022 at 15:08 UTC
    thank you both! YEs makes sense I musta needed more coffee today!
      you should also keep in mind that hash-keys are unique, any repeated value from the old hash will overwrite the last key-instance in your reversed hash.

      (the only way to avoid information loss is a hash of arrays $h2{val}=[k1,k2,k3,...] but this requires more code.)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery