Basically, I am searching two other variables, if either of them have "*" as the first character, then variable $type should be set to the character variable S, otherwise it should be set to I. The error message I am getting is: Global symbol "$type" requires explicit package name at /home/radon00/amr/sandbox/alpha/SNPtagger.pl line 48. Global symbol "$type" requires explicit package name at /home/radon00/amr/sandbox/alpha/SNPtagger.pl line 51. So I think the problem has to do with the fact that I am using the $type variable which is declared in the if block, and the $B1 and $B2 variables which were declared outside of the if block. I'm just not sure what the solution is. Here is the entire code just in case some context is needed:if ($B1=~ m/^*/ | $B2=~ m/^*/) { my $type; $type eq "S"; } else { $type eq "I"; }
Thanks for the help in advance!my $SNP_FILE="SNP.test.out"; # Will be $out in future, just hardcoded +to SNP.report for testing now. open (LINES,"<$SNP_FILE") || die ("Could not open file! \n"); # Read S +NP File <LINES>; while ($SNP_FILE=<LINES>) { my ($contig, $PP, $UPP, $Cons, $Cov, $Conflicts, $B1, $B2)=split( +'\t', $SNP_FILE); #Split line of SNP File my $ratio=sprintf("%.2f",($Conflicts/$Cov)); #Creates new variabl +e of ratio of Conflict Count/Total Coverage $PP=$PP+1; # Bump padded position coordinate by 1, as gap4 coordi +nates are off by 1 base compared to bank file $Cons=~ s/-/*/; # Replace - with gap4 pad notation in consensus v +ariable $B1=~ s/-/*/; # Replace - with gap4 pad notation in Base 1 vari +able $B2=~ s/-/*/; # Replace - with gap4 pad notation in Base 2 vari +able chomp $B2; $contig=~ s/Contig/#/; # Replace contig with number sign so gap4 +can recognize contig identifier if ($B1=~ m/^"*"/ or $B2=~ m/^"*"/) { my $type eq "S"; } else { my $type eq "I"; } my $type; print "$contig $PP $Cons $Cov $Conflicts $B1 $B2 $ratio $type \n" +; } close (LINES);
In reply to Setting Conditional Variable Based on Partial Match by Osiris1975
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |