----- Original Message ----- From: "Brian Raven" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, June 01, 2006 5:47 PM
Subject: RE: Analyzing perl array to extract maximum occuring element


my @a = qw(CMSIF FUBAR CMSIF CMSFV CMSIF FUBAR);
my %h;
my $max=0;
map { $h{$_}++; $max=$h{$_} if $h{$_} > $max; } @a;
my @b = sort { $h{$a} cmp $h{$b} } keys %h;
print "$b[0] occurs $max\n";

But surely $max ends up with the value that is already in $h{$b[0]}.

Grr, of course ;-) I wrote this late at night :-)

Petr Vileta, Czech republic
(My server reject all messages from Yahoo and Hotmail. Send me your mail from another non-spammer site please.)


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

Reply via email to