neversaint has asked for the wisdom of the Perl Monks concerning the following question:
I can only think of achieving that in two separate foreach block for A (one with B, another with C). Is there a way we can construct that with single loop (meaning even with B and C in single loop with A)? Any CPAN module that can help us with it?#!/usr/bin/perl -w use Data::Dumper; my @arA = qw( lion tiger dog cat snake); my @arB = qw( tiger dragon lion); my @arC = qw(dog phoenix); my %all; foreach my $elA (@arA) { foreach my $elB (@arB) { if ($elA eq $elB) { push @{$all{$elA}}, $elB." - from Array B"; } } } foreach my $elA (@arA) { foreach my $elC (@arC) { if ($elA eq $elC) { push @{$all{$elA}}, $elC ." - from Array C"; } } } print Dumper \%all; # Then do other thing with %all
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Selective Check of Multiple Arrays With Single Construct
by merlyn (Sage) on Apr 14, 2007 at 17:03 UTC | |
|
Re: Selective Check of Multiple Arrays With Single Construct
by blokhead (Monsignor) on Apr 14, 2007 at 15:52 UTC | |
|
Re: Selective Check of Multiple Arrays With Single Construct
by liverpole (Monsignor) on Apr 14, 2007 at 16:00 UTC | |
|
Re: Selective Check of Multiple Arrays With Single Construct
by GrandFather (Saint) on Apr 14, 2007 at 18:28 UTC | |
|
Re: Selective Check of Multiple Arrays With Single Construct
by roboticus (Chancellor) on Apr 15, 2007 at 13:54 UTC |