Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

sum of matching elements in an array

by sickboy
on Apr 13, 2001 at 10:42 UTC ( #72305=perlquestion: print w/ replies, xml ) Need Help??
sickboy has asked for the wisdom of the Perl Monks concerning the following question:

say i had a list of friends names with their favorite number.
@array=("john1","paul21","hunter7","anja21","elmer21","tom7");

I just want to know what numbers were people's favorites and
how many times each number was picked.
For the above example the output should be:
1   1 times
21  3 times
7   2 times

*****

Comment on sum of matching elements in an array
Re: sum of matching elements in an array
by dvergin (Monsignor) on Apr 13, 2001 at 11:13 UTC
    sickboy, this has the feel of a homework assignment... But whether or not that is the case, you will receive much better help if you take a stab at the problem yourself.

    For starters, without worrying about producing any Perl code, how would you break this task down into several smaller tasks. Just state the sub-tasks in plain English.

    Once you have this outline, take a shot at the first task and show us your work and describe what happened or where you are stuck and why.

    Working in steps this way, you will receive generous help. Ask us to solve your problem for you and the responses will be a bit less patient.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-07-12 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (241 votes), past polls