in reply to inverting hash / grouping values
Have you looked at the safe_reverse function in Hash::MoreUtils?
#! perl use strict; use warnings; use Data::Dump; use Hash::MoreUtils qw(safe_reverse); my %t = ( a => 1, b => 2, c => 1, d => 2, e => 1, f => 2 ); dd \%t; my %dup_rev = safe_reverse \%t; dd \%dup_rev;
Output:
0:56 >perl 729_SoPW.pl { a => 1, b => 2, c => 1, d => 2, e => 1, f => 2 } { 1 => ["c", "e", "a"], 2 => ["b", "d", "f"] } 0:57 >
Hope that helps,
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: inverting hash / grouping values
by LanX (Saint) on Sep 27, 2013 at 15:13 UTC | |
by Anonymous Monk on Sep 27, 2013 at 18:00 UTC | |
by marinersk (Priest) on Sep 27, 2013 at 15:16 UTC | |
by LanX (Saint) on Sep 27, 2013 at 15:24 UTC |
In Section
Seekers of Perl Wisdom