walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
I have an array of hashes, and I am trying to return from this array of hashes all hashes that contain two values, say cat and dog.
Here's the line I have:
UPDATE: Thanks to help from tye in the Chatterbox, I have figured out what to do here. My goal was to translate from boolean (AND, OR, NOT) to Regex, then match that against the values in an AoHes. Here's how it worked:
Here's the line I have:
Now, I know for a fact that there are hashes in this array of hashes that contain both cat and dog, but for some reason nothing is being returned.my @results = grep { grep { $_ =~ /(?=.*cat)(?=.*dog)/i } values %$_ } + @{ $lines };
UPDATE: Thanks to help from tye in the Chatterbox, I have figured out what to do here. My goal was to translate from boolean (AND, OR, NOT) to Regex, then match that against the values in an AoHes. Here's how it worked:
Both solutions worked, though I am going with the first one.grep { grep /cat/, grep /dog/, values %h } grep { grep /cat/, values %$_ } grep { grep /dog/, values %$_ } @aoh
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Checking a hash for two matching values.
by moritz (Cardinal) on Sep 17, 2013 at 04:34 UTC | |
Re: Checking a hash for two matching values.
by kcott (Archbishop) on Sep 17, 2013 at 04:39 UTC | |
by moritz (Cardinal) on Sep 17, 2013 at 05:54 UTC | |
by kcott (Archbishop) on Sep 18, 2013 at 01:02 UTC | |
Re: Checking a hash for two matching values.
by NetWallah (Canon) on Sep 17, 2013 at 05:07 UTC | |
by moritz (Cardinal) on Sep 17, 2013 at 05:51 UTC | |
by farang (Chaplain) on Sep 17, 2013 at 19:11 UTC | |
by NetWallah (Canon) on Sep 17, 2013 at 19:17 UTC |
Back to
Seekers of Perl Wisdom