Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: calculating the mode

by perigeeV (Hermit)
on Jun 10, 2002 at 10:57 UTC ( #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? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2022-12-03 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?