sdslrn123 has asked for the wisdom of the Perl Monks concerning the following question:
The above code works nicely with a one column set of data:#!/usr/bin/perl @foo= ("apple","orange","pear","pear","mango","apple"); for (@foo) { $bar{$_}++; } while ( ($k,$v) = each %bar ) { if ($v =~ 1){ print "$k appears $v time\n"; } elsif ($v !=~ 1){ print "$k appears $v times\n"; } }
For me the next stage is working with a 2-column set of data:apple orange pear pear mango apple
How would I go about creating a program that outputs:apple Tom orange Tom pear Tom mango David apple David
I am hoping to extend this to data that has lots of rows of this type of 2 column data. My thinking is playing around with hashes?APPLE appears 2TIMES associated with TOM and DAVID ORANGE appears 1TIME associated with TOM ...e.t.c
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting Data in two columns?
by ikegami (Patriarch) on Jun 15, 2006 at 00:13 UTC | |
by sdslrn123 (Novice) on Jun 15, 2006 at 13:52 UTC | |
by neniro (Priest) on Jun 15, 2006 at 14:00 UTC | |
by sdslrn123 (Novice) on Jun 16, 2006 at 21:51 UTC | |
by neniro (Priest) on Jun 16, 2006 at 22:15 UTC | |
by sdslrn123 (Novice) on Jun 21, 2006 at 10:56 UTC | |
by ikegami (Patriarch) on Jun 21, 2006 at 15:29 UTC | |
|
Re: Counting Data in two columns?
by graff (Chancellor) on Jun 15, 2006 at 03:14 UTC | |
|
Re: Counting Data in two columns?
by neniro (Priest) on Jun 15, 2006 at 08:06 UTC | |
|
Re: Counting Data in two columns?
by neniro (Priest) on Jun 15, 2006 at 10:32 UTC |