Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Count and List Items in a List

by japhy (Canon)
on Nov 01, 2005 at 15:01 UTC ( #504599=note: print w/ replies, xml ) Need Help??


in reply to Count and List Items in a List

When you think "unique" and "frequency", think of a hash. Its keys are always unique, and you can use its values as a place to store the number of times each key shows up:

for my $word (@list) { $frequency{$word}++; }
Now the %frequency hash holds each word (but only once!) and $frequency{$some_word} is the number of times $some_word appeared in @list.

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart


Comment on Re: Count and List Items in a List
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2015-07-05 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls