Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Matching values between two arrays of hashes.

by AnomalousMonk (Abbot)
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 having an uproarious good time at the Monastery: (5)
As of 2015-07-03 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls