Hi Monks,
I have an array of hashes with sports teams and I define what should be part of the list of teams as TEAMS, and then I use __DATA__ to input the list of ACTUAL_TEAMS. My goal is to then check to see what team(s) provided as ACTUAL_TEAMS are missing from TEAMS. In my example it should be only the GIANTS that are missing, but for some reason it's not working.
#!/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 (@{$TEAMS{$group}}) { # print "\t$_\n"; print "MISSING:\tSPORT:$group\tTEAM:$_\n" unless (my @type = grep /\b$ +_\b/, @{$ACTUAL_TEAMS{$group}}); } } __DATA__ NFL,JETS NFL,PATRIOTS MLB,YANKEES MLB,CARDINALS MLB,METS NBA,SIXERS NBA,CELTICS NBA,LAKERS
Any help would be greatly appreciated. Thanks
In reply to Tyring to grep array of hashes by dirtdog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |