Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Array statistics

by mfriedman (Monk)
on Jun 26, 2002 at 21:53 UTC ( #177551=note: print w/replies, xml ) Need Help??


in reply to Array statistics

To count the occurrance of things in your array:

my @array = ('foo', 'foo', 'bar', 'foo', 'bar', 'baz'); my %count; $count{$_}++ for @array; for(sort(keys(%count))) { print "$_: $count{$_}\n"; }

I'm sure you can work out how to then calculate the percentages.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2021-06-25 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (135 votes). Check out past polls.

    Notices?