ENV foo
INC bar
####
use strict;
our( @fruit, @meat, @dairy );
while (<>)
{
chomp;
my( $category, $item ) = split /\t/;
no strict 'refs';
push @$category, $item;
}
print "Fruits are: @fruit\n";
####
use strict;
my %food;
while (<>)
{
chomp;
my( $category, $item ) = split /\t/;
push @{$food{$category}}, $item;
}
print "Fruits are: @{$food{'fruit'}}\n";
####
use strict;
my( @fruit, @meat, @dairy );
my %food;
$food{'fruit'} = \@fruit;
$food{'meat'} = \@meat;
$food{'dairy'} = \@dairy;
while (<>)
{
chomp;
my( $category, $item ) = split /\t/;
$category = lc $category; # normalize
next unless exists $food{$category}; # skip unknown
push @{$food{$category}}, $item;
}
print "Fruits are: @fruit\n";