2013-12-09 117 views
2

我想了解一段循环遍历一个文件的代码,做了各种赋值,然后输入一组if语句,其中一个字符串似乎没有任何东西。 /nonsynonymous//prematureStop/与这里相比是什么?我大部分都是经验丰富的Python。这个if语句做了什么? (字符串比较)

open(IN,$file); 
    while(<IN>){ 
     chomp $_; 
     my @tmp = split /\t+/,$_; 
     my $id = join("\t",$tmp[0],$tmp[1]-1); 
     $id =~ s/chr//; 
     my @info_field = split /;/,$tmp[2]; 
     my $vat = $info_field[$#info_field]; 
     my $score = 0; 
     $self -> {VAT} ->{$id}= $vat; 
     $self ->{GENE} -> {$id} = $tmp[3]; 
     if (/nonsynonymous/ || /prematureStop/){... 

回答

6

它与当前输入行($ _)进行比较。

默认情况下,perl会在执行正则表达式匹配时自动使用当前输入行($ _),除非被重写(使用=〜)。

3
在Perl

通常情况下,如果没有给出特定的变量,假定您想使用默认变量$_。例如,while循环将来自<IN>的传入行分配给该变量,chomp $_;也可以写成chomp;,并且if语句中的正则表达式也尝试与$_匹配。