Code:
#!/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";
}
}
The above code works nicely with a one column set of data:
Code:
apple
orange
pear
pear
mango
apple
For me the next stage is working with a 2-column set of data:
Code:
apple Tom
orange Tom
pear Tom
mango David
apple David
How would I go about creating a program that outputs:
Code:
APPLE appears 2TIMES associated with TOM and DAVID
ORANGE appears 1TIME associated with TOM
...e.t.c
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?