in reply to Re: matching values in arrays
in thread matching values in arrays
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: matching values in arrays
by Animator (Hermit) on Dec 14, 2004 at 15:46 UTC | |
by Excalibor (Pilgrim) on Dec 14, 2004 at 17:29 UTC | |
by Animator (Hermit) on Dec 14, 2004 at 18:23 UTC | |
by Animator (Hermit) on Dec 14, 2004 at 18:50 UTC |