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.
In reply to Re: inverting hash / grouping values
by hdb
in thread inverting hash / grouping values
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |