in reply to inverting hash / grouping values
It can be done this way
my %ih = map { my $k = $_; $k => [ grep { $h{$_} eq $k } keys %h ] } k +eys {reverse %h};
but it must be much slower than the simple code you have shown. Using keys and reverse to get the list of the unique values of the hash and then repeatedly grep on the keys of the original hash must be rather slow.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: inverting hash / grouping values
by LanX (Saint) on Sep 27, 2013 at 15:06 UTC | |
by hdb (Monsignor) on Sep 27, 2013 at 18:13 UTC | |
by LanX (Saint) on Sep 27, 2013 at 18:26 UTC | |
by hdb (Monsignor) on Sep 28, 2013 at 08:26 UTC | |
by LanX (Saint) on Sep 28, 2013 at 11:34 UTC |
In Section
Seekers of Perl Wisdom