Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
go ahead... be a heretic
 
PerlMonks  

Re: Matching values between two arrays of hashes.

by AnomalousMonk (Monsignor)
on Oct 31, 2012 at 19:15 UTC ( #1001734=note: print w/ replies, xml ) Need Help??


in reply to Matching values between two arrays of hashes.

I'm not entirely sure I understand your requirement, but if I do, this might fill the bill:

>perl -wMstrict -MData::Dump -le "my @subnets = ( { qw(id 1 location_id 30 subnet 255.255.255.0) }, { qw(id 2 location_id 13 subnet 255.255.254.0) }, { qw(id 3 location_id 19 subnet 255.255.0.0 ) }, ); dd \@subnets; ;; my @filers_info = ( { qw(id 1 location_id 19 info blah1) }, { qw(id 2 location_id 30 info blah1) }, { qw(id 3 location_id 99 info yada1) }, ); dd \@filers_info; ;; my %locations = map { $_->{location_id}, 1 } @subnets; dd \%locations; ;; my @filer_ids = grep $locations{ $_->{location_id} }, @filers_info; dd \@filer_ids; " [ { id => 1, location_id => 30, subnet => "255.255.255.0" }, { id => 2, location_id => 13, subnet => "255.255.254.0" }, { id => 3, location_id => 19, subnet => "255.255.0.0" }, ] [ { id => 1, info => "blah1", location_id => 19 }, { id => 2, info => "blah1", location_id => 30 }, { id => 3, info => "yada1", location_id => 99 }, ] { 13 => 1, 19 => 1, 30 => 1 } [ { id => 1, info => "blah1", location_id => 19 }, { id => 2, info => "blah1", location_id => 30 }, ]


Comment on Re: Matching values between two arrays of hashes.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (16)
As of 2014-04-18 18:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls