http://qs1969.pair.com?node_id=173074


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{$_}++; }