http://qs321.pair.com?node_id=484582


in reply to Re^2: Why does this happen?
in thread Why does this happen?

I'd keep them separate in case ($#qbase != $#sbase), and since you're not doing anything else with the index, just loop through them all...
foreach $qbase ( @qbase ) { if ( uc($qbase) eq 'N' ) { ++$ncount; } } foreach $sbase ( @sbase ) { if ( uc($sbase) eq 'N' ) { ++$ncount; } }
or more concisely...
do { $ncount++ if /n/i } foreach ( @qbase, @sbase );
Update: disregard, read the OP wrong

Update: re-read, and the answer doesn't take into account if subj_sequence is n and query is not...
foreach my $idx ( 1..$#query_sequence ) { if ( $query_sequence[$idx] =~ /n/i && $subj_sequence[$idx] !~ /n/i ) + { $ncount++; } elsif ( $subj_sequence[$idx] =~ /n/i && $query_sequence[$idx] !~ / +n/i ) { $ncount++; } }
(Note that it is assumed that $#query_sequence = $#subj_sequence)

Update: again..
$ncount = grep { ($qbase[$_] =~ /n/i && $sbase[$_] !~ /n/i) || ($qbase +[$_] !~ /n/i && $sbase[$_] =~ /n/i) } 1..$#qbase;