perl - perl-关闭if语句时语法错误

标签 perl if-statement syntax-error

我正在尝试编写一个脚本,以针对提供每个GI号的基因组位置的先前生成的文件搜索BLAST输出。但是,我遇到三个与关闭IF语句有关的语法错误。作为Perl的新手,我无所适从。谁能帮我?我已经复制了代码并标记了令人讨厌的右括号。我做了快速检查,以确保所有定界符都平衡。

#!/usr/bin/perl -w

#decided to have input file entered in command line
#call program followed by genome name. 
#the program assumes that a file with the extensions ptt and faa exist in the same dirctory. 


#####INPUT Name of multiple seq file containing ORF of genome, open file and assign IN filehandle ############# 

unless(@ARGV==2) {die "usage: perl nucnums.pl BLAST_output_filename query.ref subject.ref\n\nSubject is the database you made with FormatDB or MakeBlastDB.\n\nQuery is the other file";}

$blastname=$ARGV[0];  
$queryname=$ARGV[1];
$subjectname=$ARGV[2];
@nameparts=split(/\./, $blastname);
$ofilename="$blastname[0]"."pos";
open(INBLAST, "< $blastname") or die "cannot open $blastname:$!";

open(OUT, "> $ofilename") or die "cannot open $ofilename:$!";
$line=<INBLAST>;
print OUT $line;
while (defined ($line=<INBLAST>)){ # read through rest of table line by line
    if ($line=/^g/){
        @parts=split/\t/,$line;
        @girefq=split/\|/,$parts[0];
        $ginumq = ($girefq[1]);
        $postartq = $parts[6];
        @girefs=split/|/,$parts[1];
        $ginums = ($girefs[1]);
        $postarts = $parts[8];
        open(INQUER, "< $queryname") or die "cannot open $queryname:$!"; 
        open(INSUBJ, "< $subjectname") or die "cannot open $subjectname:$!";
        SCOOP: while (defined ($locq=<INQUER>)){
            @locsq=split/\t/,$locq
            if $locsq[0] = $ginumq{
                $posq = $locsq[1] + $postartq - 1;
                } # <- Syntax error

            }
        close(INQUER);
        SLOOP: while (defined ($locs=<INSUBJ>)){
            @locsq=split/\t/,$locs
            if $locss[0] = $ginums {
                $poss = $locss[1] + $postarts - 1;
                } # <- Syntax error

            }
        close(INSUBJ);
        print "$ginumq at position $posq matches with $ginums at position $poss \n" or die "Failed to find a match, try changing the order of the REF files";
        print OUT "$ginumq\t$posq\t$ginums\t$poss\t$parts[2]\t$parts[3]\t$parts[4]\t$parts[5]\t$parts[6]\t$parts[7]\t$parts[8]\t$parts[9]\t$parts[10]\t$parts[11]\t$parts[12]\n";
        } # <- Syntax error
    }

close(OUT);
close(INBLAST);

最佳答案

您需要更改:

@locsq=split/\t/,$locs
if $locss[0] = $ginums {

像这样:
@locsq=split/\t/,$locs;
if ($locss[0] == $ginums) {
$locsq[0]也是如此。如果要比较字符串而不是数字,请使用eq而不是==

更新:感谢Zaid指出缺少的分号。

关于perl - perl-关闭if语句时语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19323910/

相关文章:

perl - 等效于 "shift"的散列以创建 $class->next() 方法

multithreading - 相同版本但具有不同配置选项的两个 perls 之间的兼容性?

perl - 使用SSH实时记录到文件?

c++ - switch 优于 if-else 语句的优点

java - projecteuler-3 质因数除法中的 if vs while 循环

python - Python语法错误?

ruby - ruby 中的无效功能

vba - 由于语法错误(录制时)或对象定义错误(运行时)而无法运行 VBA

perl - Template Toolkit 中的 [% %] 和 [%- -%] 有什么区别?

javascript - `if` 无法检查 <img> src 的值