Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Tyring to grep array of hashes

by kennethk (Abbot)
on Feb 07, 2017 at 15:55 UTC ( [id://1181303]=note: print w/replies, xml ) Need Help??


in reply to Tyring to grep array of hashes

my @type = grep /\b$_\b/, @{$ACTUAL_TEAMS{$group}}
This will always be true, because in the grep, $_ equals the active element -- you've written a tautology. Perhaps you mean:
#!/usr/bin/env perl use strict; my %ACTUAL_TEAMS; my %TEAMS = ( "NFL" => [ 'JETS', 'PATRIOTS', 'GIANTS', ], "MLB" => [ 'YANKEES', 'METS', 'CARDINALS', ], "NBA" => [ 'SIXERS', 'CELTICS','LAKERS', ], ); while (<DATA>) { chomp; next if /^\s*$/ || /^\#/; my $aref = [split /,/, $_]; push( @{$ACTUAL_TEAMS{$aref->[0]}}, $aref->[1]); } foreach my $group (keys %TEAMS) { #print "The members of $group are\n"; foreach my $team (@{$TEAMS{$group}}) { # print "\t$_\n"; print "MISSING:\tSPORT:$group\tTEAM:$team\n" unless (my @type = grep / +\b$team\b/, @{$ACTUAL_TEAMS{$group}}); } } __DATA__ NFL,JETS NFL,PATRIOTS MLB,YANKEES MLB,CARDINALS MLB,METS NBA,SIXERS NBA,CELTICS NBA,LAKERS

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2024-04-16 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found