Match elements in same position of 2 arrays
14:46 13 Nov 2011

I have 2 arrays

@a = qw/ A B C D E     /;
@b = qw/ B B C       A /;    

I need to check if the same element appear in the same position of each array:

e.g.

$a[2] = "B";
$b[3] = "C";

if so count the number of times this happened it need to disregard any blank elements

e.g.

$a[6] =  ;
$b[6] =  ;

I tried intersect eq == cmp etc but I can't quite get it and not quite sure.

Here's my code so far:

#!/usr/bin/perl -w

my @a = ;
my @b = ;

$occurs = 0; #Using eq
foreach my $letter (@a) {
    if (my $letter2 (@a) eq $letter) { #Syntax error here
        $count ++;
    }
} #syntax error here
arrays perl compare