I'm really confused about how to pass a variable into different statement. My code is:
use warnings;
use strict;
use feature qw(say);
say "Please enter the first sequence:";
my $sequence1 = <STDIN>;
$sequence1 = chomp $sequence1;
say "Please enter the second sequence:";
my $sequence2 = <STDIN>;
$sequence2 = chomp $sequence2;
if (length $sequence1 < length $sequence2){
my $sequence2_new = substr $sequence2, length $sequence1;
}
my @sequence1 = split(',', $sequence1);
my @sequence2 = split(',', $sequence2_new);
my $element = scalar @sequence1;
my $num = 0;
for ($a = 0; $a < $element; $a++){
if ($sequence1[$a] = $sequence2[$a]){
$num++;
}
}
my $score = $num % length $sequence2;
say "The alignment score is: $score";
In this case, this program will return a Global symbol "$sequence2_new" requires explicit package name at alignment_sequence.pl line 19.
mistake. If I move the "my" declaration in front of if statement in line 14 like my $sequence2_new;
it will give me Use of uninitialized value $sequence2_new in split at alignment_sequence.pl line 20, <STDIN> line 2.
warning.