Yes, I do. And I think I have understood what you are looking for. But I do not think it is possible. In order to go from your hash to the inverted one, one has to look across elements, so most functionals will not work.
Best would be to just add your code to some of the core modules, but then it would be in competition with Hash::MoreUtils which does - as you point out below - the same but not quite.
UPDATE: I can hide the push in reduce. But I don't think that this is what you are looking for either...
use strict; use warnings; use List::Util 'reduce'; use Data::Dumper; my %t = ( a => 1, b => 2, c => 1, d => 2, e => 1, f => 2, g => 3 ); my $i = reduce { $a = { $t{$a} => [ $a ] } unless ref $a; push @{ $a->{ $t{$b} } }, $b; $a } keys %t; print Dumper $i;
In reply to Re^5: inverting hash / grouping values
by hdb
in thread inverting hash / grouping values
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |