sunil9009 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Perl Monks, Happy Thanks giving. I am interested in getting the array of People residing in US, @ValidLocations. Banging my head and at last given up. Can you please help me with the following code.
#!/usr/bin/perl use strict; use warnings; my @ValidLocations = ('Lynnwood','Edmonds'); my $ref = { 'US/Seattle/WA' => ['Smith','Eric','Sam'], 'US/WA/Lynnwood' => ['John','Chuck','Ram','Lynda'], 'US/WA/Everette' => ['Sun','Rick','Raj'], 'US/Edmonds/WA' => ['Ken','Josh','Matt'], 'IN/Banglore/KA' => ['Anil','Dada','Kaka'] }; my @keys = keys %{$ref}; foreach my $loc (@ValidLocations) { foreach my $k(@keys){ if (($k =~ /US/) && ($k =~ /$loc/)) { print "@{$ref->{$k}} \n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: iterating 2 arrays
by Athanasius (Archbishop) on Nov 29, 2013 at 03:00 UTC | |
|
Re: iterating 2 arrays
by GrandFather (Saint) on Nov 29, 2013 at 02:34 UTC | |
by sunil9009 (Acolyte) on Nov 29, 2013 at 04:27 UTC | |
by kcott (Archbishop) on Nov 29, 2013 at 05:06 UTC | |
by GrandFather (Saint) on Nov 29, 2013 at 05:23 UTC | |
|
Re: iterating 2 arrays
by kcott (Archbishop) on Nov 29, 2013 at 04:51 UTC | |
|
Re: iterating 2 arrays
by KurtZ (Friar) on Nov 29, 2013 at 02:56 UTC |