Dear All, I am new in Perl and I am trying to solve the following comparison.
I have two arrays:
@A = ("Red", "Green", "Yellow");
@B = ("Yellow", "Black","Yellow","Red", "White", "Yellow");
In array A, each element occurs only once.
In array B, each element can occur zero, one or many times.
For every element in A, the code should lists the position at which it is present in B and give the output as following:
> Red at index 3.
> Green is missing.
> Yellow at index 0, 2 and 5.
> Elements from B were detected 4 times in A.
I tried the following but I cannot figure out how to list indexes of elements after comparing two arrays
foreach $x (@A){
foreach $y (@B){
if ($y eq $x){
print "$y\n";
}
elsif ($x ne$y){
print "$x";
}
}
}
Can someone please, help me? Thank you very much in advance!
Rebi
Have a look in the PERL cpan libs, there are librairies to work with arrays and one of them is to intersect arrays
Hi ,
Your post don't have links with bio-informatics you should post it on stackoverflow.
I still give you a link where you can find what you are looking for Perl tuto.
Is this a homework/assignment question?