in reply to Selective Check of Multiple Arrays With Single Construct
You may find List::Compare helps, but I can't help thinking there is a bit of XY going on here. What is the bigger problem you are trying to solve?
A cleaner and easier to maintain version of your sample code is:
use strict; use warnings; use Data::Dumper; my @arA = qw(lion tiger dog cat snake); my @arB = qw(tiger dragon lion); my @arC = qw(dog phoenix); my @arD = qw(lion wolf mouse); my %all; my %arrays = (b => \@arB, c => \@arC, d => \@arD); my %aElts; @aElts{@arA} = (1) x @arA; for my $array (keys %arrays) { for my $elt (@{$arrays{$array}}) { next unless $aElts{$elt}; push @{$all{$elt}}, "from Array $array"; } } print Dumper \%all;
Prints:
$VAR1 = { 'lion' => [ 'from Array b', 'from Array d' ], 'dog' => [ 'from Array c' ], 'tiger' => [ 'from Array b' ] };
|
|---|