[ltp] perl question:
James Hawtin
linux-thinkpad@www.bm-soft.com
Wed, 23 May 2001 16:58:00 +0000 (GMT)
Ok I am not going to do your homework for you.... you don't learn that
way... But have you considerd using a hash? Using the key as the number,
increment the value that is hashed each time you see the value(key), then
sort the hash based on hash values, depending on how you sort it, it will
be the first or last number.
James
On Wed, 23 May 2001, ROOT, DAN wrote:
> I know this has little to nothing to do with Linux on ThinkPads other than I
> use my ThinkPad for school, but thought I might ask anyway. For my class I
> have created a random numeric array which has 10 elements. I am suppose to
> do a few things with it, but the one thing I seem to be a little stumped on
> is finding the most common occurrence of an element and then returning it's
> value.
>
> Example:
>
> @array = 2 4 6 3 4 8 1 9 7 5
>
> Mode = 4
>
> How do I capture that "4" is the most common element of the array? I have
> tried using grep and a loop, but I am not getting the results I had hoped
> for. Any pointers from anyone would be muchly appreciated.
>
> Thanks!
>
> Dan Root
> Safeco Information Systems
> danroo@safeco.com
> 206-545-3250
>
>
>
> ----- The Linux ThinkPad mailing list -----
> The linux-thinkpad mailing list home page is at:
> http://www.bm-soft.com/~bm/tp_mailing.html
>
----- The Linux ThinkPad mailing list -----
The linux-thinkpad mailing list home page is at:
http://www.bm-soft.com/~bm/tp_mailing.html