in reply to Counting unique elements in an array
my @array = qw(bb aa dd cc aa aa cc aa aa cc); print "$_\n" for uniq_ordered_count( \@array ); sub uniq_ordered_count { my $list = shift; my %count; $count{ $_ }++ for @$list; return map { exists $count{$_} ? "$_ - " . delete $count{$_} : () +} @$list; }
Cheers - L~R
Update: Per bart's recommendation. I changed the wording of original order to first appearance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting unique elements in an array
by Anonymous Monk on Feb 08, 2005 at 14:15 UTC |