in reply to Selective Check of Multiple Arrays With Single Construct
If something from array A was not found in the other arrays, it will exist in %all with an undefined value. You can grep these out at the end if you prefer.use Data::Dumper; my @arA = qw( lion tiger dog cat snake); my @arB = qw( tiger dragon lion); my @arC = qw(dog phoenix); my %all; @all{@arA} = (); for (@arB) { next unless exists $all{$_}; push @{$all{$_}}, "$_ - from array B"; } for (@arC) { next unless exists $all{$_}; push @{$all{$_}}, "$_ - from array C"; } print Dumper \%all;
It would be easy to make this extensible (for arrays D, E, F, etc) if @arB, @arC were named like @{$arrays{B}} and @{$arrays{C}}. I'll leave that to you.
blokhead
|
|---|