If you're interested in the unique values, I'd suggest adding another level to your hash, something like:
use strict; use warnings; my %hash; while (<DATA>) { s/\s+$//; my ($key1, $key2) = split /\s+/, $_; $hash{$key1}{$key2}++; } for my $k1 (sort keys %hash) { print "$k1: ", join(", ", sort keys %{$hash{$k1}}), "\n"; } __DATA__ Lemon Juice Lemon Cake Apple Cider Lemon Cake Apple Butter Apple Sauce Apple Juice Lemon Juice
Note: The code is untested, but I'd expect output like:
Apple: Butter, Cider, Juice, Sauce Lemon: Cake, Juice
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: Unique key/value pair in Multiple key values pair in Hash
by roboticus
in thread Unique key/value pair in Multiple key values pair in Hash
by Seek_Knowledge
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |