in reply to How to find number of unique elemenst in array

My constraint: Don't use a hash!

my @array = qw/A B C B D B D/; my $c=1; foreach my $k (sort @array) { next if --$c; $c= scalar grep { $_ eq $k } @array; print "There are $c element(s) of $k\n"; }

Update: Fixed thanks to gashos coment.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: How to find number of unique elemenst in array
by gasho (Beadle) on Dec 01, 2008 at 18:45 UTC
    It failed test with my @array = qw/history historyA historyB history historyA D/;
    (: Life is short enjoy it :)