This solution is nice, and the hash is probably the way to go with it, but if the arrays contain repeated numbers, (i.e. their intersection is not void) it will probably fail (as it will always mark the last array, instead of the first one, or all of them)...
Expanding your solution a bit will yield this:
my %which; do { push @{ $which{$_} } => "array1" } for @array1; do { push @{ $which{$_} } => "array2" } for @array2; do { push @{ $which{$_} } => "array3" } for @array3; my @pairs = @array4; while (my ($one,$two) = splice(@pairs,0,2)) { print "$one and $two are in (@{$which{$one}}) and (@{$which{$two} +}) respectively\n"; }
which is more generic and works even if the numbers are shared by any of the arrays...
Great idea, anyway!
--
our $Perl6 is Fantastic;
In reply to Re^2: matching values in arrays
by Excalibor
in thread matching values in arrays
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |