in reply to Re^2: Counting Data in two columns?
in thread Counting Data in two columns?
The easiest way is to convert
FLINTSTONES -- BARNEY, FRED, WILMA JETSONS -- MAX, TONY, WILMA SIMPSONS -- LISA, BARNEY, WILMA, HOMER ALCATRAZ -- ELIJAH, MAX, WILMA
to
my %is_in_show = ( MAX => [ 'JETSONS', 'ALCATRAZ' ], WILMA => [ 'FLINTSTONES', 'JETSONS', 'SIMPSONS', 'ALCATRAZ' ], HOMER => [ 'SIMPSONS' ], ELIJAH => [ 'ALCATRAZ' ], ... );
when you read the file. The following accomplishes this:
while (<FILE>) { chomp; my ($show, $names) = split(/ -- /); my @names = split(/, /, $names); foreach my $name (@names) { push(@{$is_in_show{$name}}, $show); } }
|
|---|