my @date = grep /$date/,@{$countries${cntry_of_issue}})That code doesn't even compile. Try this instead:
my @dates = grep /$date/, @{ $countries{$cntry_of_issue} };
I got rid of the unmatched right paren, added a semicolon, and moved the dollar sign to the right of the curly bracket to form the scalar variable $cntry_of_issue, rather than the bareword cntry_of_issue.
Here is a self-contained example which seems to work for me:
Prints:use warnings; use strict; use Data::Dumper; my %countries; while (<DATA>) { chomp; next if /^\s*$/ || /^\#/; my $aref = [split /,/, $_]; push( @{$countries{$aref->[2]}}, $aref->[5]); } my $date = 20100101; my $cntry_of_issue = 'CH'; my @dates = grep /$date/, @{ $countries{$cntry_of_issue} }; print Dumper(\@dates); __DATA__ 978,XBRN,CH,Berne Stock Exchange,2010,20100101 978,XBRN,CH,Berne Stock Exchange,2010,20100102 978,XBRN,CH,Berne Stock Exchange,2010,20100321 978,XBRN,CH,Berne Stock Exchange,2010,20100324
$VAR1 = [ '20100101' ];
In reply to Re: Trouble grepping values when hash contains multiple values per key
by toolic
in thread Trouble grepping values when hash contains multiple values per key
by dirtdog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |