Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Perl style... help me figure this out.

by ikegami (Patriarch)
on Feb 12, 2012 at 04:18 UTC ( [id://953281]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl style... help me figure this out.
in thread Perl style... help me figure this out.

Yeah, you can use an array instead of a hash.
my %items = map { $_ => 1 } ( 'APPLES', 'SILVER', ); my @groups = ( [ 'cookies', [ 'CHOCOLATE CHIP', 'PEANUT BUTTER' ] ], [ 'previous metals', [ 'SILVER', 'GOLD', 'PLATINUM' ] ], ); my $lover; for my $group (@groups) { my ($group_name, $group_members) = @$group; if ( grep $items{$_}, @$group_members ) { print "This guy loves $group_name.\n"; ++$lover; } } if (!$lover) { print "This guy loves nothing.\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://953281]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-29 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found