dirtdog has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tyring to grep array of hashes
by kennethk (Abbot) on Feb 07, 2017 at 15:55 UTC | |
|
Re: Tyring to grep array of hashes
by 1nickt (Canon) on Feb 07, 2017 at 16:20 UTC | |
by dirtdog (Monk) on Feb 07, 2017 at 16:49 UTC | |
by hippo (Archbishop) on Feb 07, 2017 at 17:15 UTC | |
by 1nickt (Canon) on Feb 07, 2017 at 17:13 UTC | |
by dirtdog (Monk) on Feb 07, 2017 at 17:25 UTC | |
|
Re: Tyring to grep array of hashes (updated)
by haukex (Archbishop) on Feb 07, 2017 at 16:10 UTC | |
by Athanasius (Archbishop) on Feb 07, 2017 at 16:41 UTC | |
by haukex (Archbishop) on Feb 07, 2017 at 21:21 UTC | |
by Anonymous Monk on Feb 07, 2017 at 16:44 UTC |