in reply to Re: Module Bloat and the Best Solution
in thread Module Bloat and the Best Solution
my %tmp = map { $_ => 1} @foo; my @uniq_foo = sort keys %tmp;
I personally believe that you can avoid the intermediate step:
my @uniq_foo = sort keys %{ {map { $_ => 1} @foo} };
Yes, it's a dirty trick! :)
And as far as your example with three arrays and the respective uniq'd incarnations is concerned, whichever way you choose, I would go with a HoA instead:
my %uniq = map { my %tmp = map { $_ => 1} @$_; $_ => [sort keys %tmp]; } keys %arrays;
or
my %uniq = map { $_ => [sort keys %{ {map { $_ => 1} @$_} }]; } keys %arrays;
or
my %uniq = map { my %saw; $_ => [map !$saw{$_}++, @$_]; } keys %arrays;
or
my %uniq = map { $_ => [uniq @$_] } keys %arrays;
|
---|