in reply to Tyring to grep array of hashes
This will always be true, because in the grep, $_ equals the active element -- you've written a tautology. Perhaps you mean:my @type = grep /\b$_\b/, @{$ACTUAL_TEAMS{$group}}
#!/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.
|
|---|