in reply to Perl style... help me figure this out.
The direly needed improvements:
One of many ways:
my %items = map { $_ => 1 } ( 'APPLES', 'SILVER', ); my %groups = ( 'cookies' => ['CHOCOLATE CHIP', 'PEANUT BUTTER'], 'previous metals' => ['SILVER', 'GOLD', 'PLATINUM'], ); my $lover; for my $group_name (keys(%groups)) { if ( grep $items{$_}, @{ $groups{$group_name} } ) { print "This guy loves $group_name.\n"; ++$lover; } } if (!$lover) { print "This guy loves nothing.\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl style... help me figure this out.
by jaydstein (Novice) on Feb 07, 2012 at 17:31 UTC | |
by ikegami (Patriarch) on Feb 12, 2012 at 04:18 UTC | |
by Marshall (Canon) on Feb 08, 2012 at 22:06 UTC |