Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Checking a hash for two matching values.

by NetWallah (Canon)
on Sep 17, 2013 at 05:07 UTC ( #1054387=note: print w/replies, xml ) Need Help??


in reply to Checking a hash for two matching values.

Arguably more readable than those above ... (IMHO, code matches problem description closer)
my @found= grep { my %r = reverse %$_; exists $r{cat} && exists $r{d +og}} @pets;

             My goal ... to kill off the slow brain cells that are holding me back from synergizing my knowledge of vertically integrated mobile platforms in local cloud-based content management system datafication.

Replies are listed 'Best First'.
Re^2: Checking a hash for two matching values.
by moritz (Cardinal) on Sep 17, 2013 at 05:51 UTC

      It's easy enough to add case insensitivity to NetWallah's code with fc or lc.

      For v5.16 or newer:

      use v5.16; ... my @found= grep { my %r = reverse map fc, %$_; exists $r{cat} && exists $r{dog} } @pets;
      For older versions as well:
      my @found= grep { my %r = reverse map lc, %$_; exists $r{cat} && exists $r{dog} } @pets;

      Hmm - I did not notice any hints of requiring case-insensitivity, but in any case, that requirement is easily accommodated in my code by adding a "map {lc}" .
      my @found= grep { my %r = map{lc} reverse %$_; exists $r{cat} && exis +ts $r{dog}} @pets;

                   My goal ... to kill off the slow brain cells that are holding me back from synergizing my knowledge of vertically integrated mobile platforms in local cloud-based content management system datafication.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1054387]
help
Chatterbox?
[ovedpo15]: If I use "unless(opendir(my $dir, $test_dir))" why does it give me error "Global symbol "$dir" requires explicit package name at" if I used "my"? If I use my $dir before the opendir it works.. but why?

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-04-22 15:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?