Sometimes it amuses me to place arbitrary constraints on myself in answering a question. In this case, I decided I was limited to one statement and no (declared) variables other than the input.use strict; use warnings; use List::Util "reduce"; use Lingua::EN::Inflect "inflect"; use Algorithm::Loops "MapCar"; my @array = qw/A B C B D B D/; print map { map ( inflect("There PL(is,$_) $_ PL(element,$_) of "), $_->[1] +), "$_->[0]\n" } MapCar { [@_] } map { [sort keys %$_], [@$_{sort keys %$_}] } reduce { $a->{$b||$b}++; $a } {}, @array ;
Update: replaced an ugly reduce with MapCar.
Update: additional topicalization
In reply to Re: How to find number of unique elemenst in array
by ysth
in thread How to find number of unique elemenst in array
by gasho
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |