Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Common hash keys

by casiano (Pilgrim)
on Jun 07, 2008 at 10:01 UTC ( [id://690822]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      DB<1> %a = (a => 1, b =>2, c => 3); %b = (b =>2, c => 1, d => 4)
      DB<2> $seen{$_}++ for (keys(%a), keys(%b))
      DB<3> x grep { $seen{$_} > 1 } keys(%seen)
    0  'c'
    1  'b'
    
  2. or download this
      DB<1> use List::Util qw{first}
      DB<2> %a = (a => 1, b =>2, c => 3); %b = (b =>2, c => 1, d => 4)
      DB<3> x first { ++$seen{$_} > 1 } (keys(%a), keys(%b))
    0  'c'
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://690822]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-19 20:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found