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] = ;
comments are most appreciated I like to understand the script.
I tried intersect eq == cmp etc but I can’t quite get it and not quite sure
Thanks in advance.
Here’s my code so far:
#!/usr/bin/perl -w
my @a = <FILE1>;
my @b = <FILE2>;
$occurs = 0; #Using eq
foreach my $letter (@a) {
if (my $letter2 (@a) eq $letter) { #Syntax error here
$count ++;
}
} #syntax error here
The definition of blank here needs to be clarified. Is it an empty string? An
undefined value? Whitespace?I’m assuming any element with no non-whitespace characters as blank in the example below, which shows how it could be done with the
each @arrayconstruct: