counting word occurances

R

Rodrick Brown

apple
orange
pear
pear
magno
apple

Given the following data can someone show me example code on how to count
how many of each different fruit

ie.

output should be somehting like

apple 2
orange 1
pear 1
mango 1

Note this isnt homework or anyting.
 
R

Randal L. Schwartz

Rodrick> Note this isnt homework or anyting.

Ding ding ding. Homework alert. :)

Not to mention "unable to tell a dead group from a live one".
 
J

Jürgen Exner

Rodrick said:
apple
orange
pear
pear
magno
apple

Given the following data can someone show me example code on how to
count how many of each different fruit

Well, assuming @foo contains the list of fruit, then

for (@foo) {
$bar{$_}++;}

will place the count in %bar.
output should be somehting like

The rest is left as an excercise.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top