Bowie Bailey wrote:

> $Bill Luebkert wrote:
> 
>>Lots of ways to do it.
>>I'd probably just map it into a hash increasing the count by one
>>for each occurence - then sort the hash by value.
>>
>>my @a = qw(CMSIF FUBAR CMSIF CMSFV CMSIF FUBAR);
>>my %h;
>>
>>map { $h{$_}++ } @a;
>>my @b = sort { $h{$a} cmp $h{$b} } keys %h;
>>print "$b[0]\n";
> 
> 
> You are using a string comparison to sort numbers.  This will cause
> problems once you get to the double digits.

Correct - I was looking at the keys rather than the values.

The map isn't really needed either (and it's tacky using side-effects) :

$h{$_}++ foreach @a;
my @b = sort { $h{$a} <=> $h{$b} } keys %h;

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to