[ltp] perl question:

Vivek Dasmohapatra linux-thinkpad@www.bm-soft.com
Wed, 23 May 2001 16:30:03 +0100 (BST)


On Wed, 23 May 2001, ROOT, DAN wrote:

> I know this has little to nothing to do with Linux on ThinkPads other than I

One of the perl lists would be a better place to ask this question, see
http://lists.perl.org/

However, since you are hgere, and I'm bored...:

use strict; # you will use strict. really.

my $max  = 0;
my $maxk = 0;
my %c    = ();
my @a = (1,2,3,4,5,6,3,2,4,5,3,23,5,6,2,3,2,4,7,8,4,2,5,8,5,5);

grep { $c{$_}++; ($c{$_} > $max) && (($maxk,$max) = ($_,$c{$_})) } @a;

print(STDOUT $maxk,"\n");

NOTE: This makes no attempt to resolve tha case where you have ties for
the top rank: first one to make it there wins. Also, this is tersely
written - if you are using this for didactic purposes, or putting it in
some code you need to maintain, rather than a genuine one-shot, I
reccomend writing it out more verbosely.

-- 
Vivek


----- The Linux ThinkPad mailing list -----
The linux-thinkpad mailing list home page is at:
http://www.bm-soft.com/~bm/tp_mailing.html