|go ahead... be a heretic|
Finding Combinations of Pairsby zod (Scribe)
|on Jan 14, 2009 at 03:21 UTC||Need Help??|
zod has asked for the
wisdom of the Perl Monks concerning the following question:
I have a file that has a list of words on each line, let's say:
dog monkey cat cat ball stone monkey iron cat zoo
What I need to do is find out which two-word combinations (order does not matter) on each line are most common in the file.
So I need to generate all pair combinations for each line and then figure out which pair combo is the most common over all the lines.
So, the first line should generate:
dog monkey dog cat monkey cat
I figured I should dump each line into an array and then generate the pair combos for each array. So, I started with tye's Finding all Combinations node:
But, alas, I'm stuck already as I'm not sure how to generate only _pair_ combinations rather than every possible combo.
Can anyone point me in the right direction? My spidey sense tells me I should use a hash. But not sure where to start...