Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: calculating the mode

by perigeeV (Hermit)
on Jun 10, 2002 at 10:57 UTC ( [id://173074]=note: print w/replies, xml ) Need Help??


in reply to calculating the mode

There's many things going south here. As zejames says you're not openning and using the correct files (you might want to check the success of the open, too). You have placed the subs within the scope of the while loop. You never actually call the mode function. You're passing odd_median() an array ref, but inside odd_median() you treat it like a regular array. You never actually print anything to OUTFILE, and if you did you would overwrite anything it previously held.

As frankus mentions, the canonical way to count the occurance of elements is to use a hash with each array element as the key and the count as the value:

for(@array) { $hash{$_}++; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://173074]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-19 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found