Li, Aiguo (NIH/NCI) [E] wrote:
Hello,
Hello,
I have a programming questions to you all,
I have three arrays: arrayA1, arrayA2, (arrayA1 and arrayA2 are same
length) and array B. Using the following code I created the fourth
arrayC that contain intersection elements between arrayA1 and arrayB.
Now I need to get the corresponding elements in arrayA2 into arrayD.
Since arrayA1 and arrayA2 are same length make a single array of arrays:
my @A = (
[ 'zero', 'one' ],
[ 'two', 'three' ],
[ 'four', 'five' ],
[ 'six', 'seven' ],
[ 'eight', 'nine' ],
);
my @B = ( 'two', 'six' );
my @CD;
for my $array ( @A ) {
if ( grep $_ eq $array->[ 0 ], @B ) {
push @CD, [ @$array ];
}
}
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/