in reply to Counting unique elements in an array

Similar to other solutions, but using grep and sort:
@array = qw (aa bb cc aa aa cc cc dd aa aa); grep {$count{$_}++} @array; print "$_ - $count{$_}\n" foreach sort keys %count;
Or search for "count unique array" in Super Search :-)

Replies are listed 'Best First'.
Re^2: Counting unique elements in an array
by Jasper (Chaplain) on Feb 08, 2005 at 12:21 UTC
    I think you don't understand the 'grep' function. map in a void context I can understand, but grep? Doesn't make sense.

    By the way, why are there so many replies to an obvious homework problem the answer to which can be found in an FAQ. Crazy!