Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How can I count and display unique items in an array?

by joshua (Pilgrim)
on Jun 20, 2002 at 23:05 UTC ( [id://176192]=note: print w/replies, xml ) Need Help??


in reply to How can I count and display unique items in an array? (was: array counting)

This oughta work...
use strict; my @array = qw(foo bar foobar foobar bar bar bar bar foo foo foo foo b +ar foobar); my %hash; $hash{$_}++ foreach @array; print "Content-type: text/plain\n\n"; foreach (keys %hash) { print "$_ appears $hash{$_} times\n"; }
The above will return...
foobar appears 3 times foo appears 5 times bar appears 6 times

Joshua

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found