2016-02-24 33 views
-1

全部。忽略前兩行##中的perl

我是編程中的新手,特別是在Perl中。我想跳過數據集中的前兩行。

這些是我的代碼。

while (<PEPTIDELIST>) { 
     next if $_ !=~ "##"; 
     chomp $_; 
     @data = split /\t/; 
     chomp $_; 
     next if /Sequence/; 
     chomp $_; 
    $npeptides++; 
# print "debug: 0: $data[0] 1: $data[1] 2: $data[2] 3: 
$data[3]  
\n" if ($debug); 
    my $pepseq = $data[1]; 
    #print $pepseq."\n"; 
    foreach my $header (keys %sequence) { 
    #print "looking for $pepseq in $header \n"; 
    if ($sequence{$header} =~ /$pepseq/) { 
     print "matched $pepseq in protein $header" if ($debug); 
     # my $in =<STDIN>; 

     if ($header =~ /(ENSGALP\S+)\s.+(ENSGALG\S+)/ ) { 
      print "debug: $1 $2 have the pep = $pepseq \n\n" if ( 
$debug); 
      my $lprot = $1; 
      my $lgene = $2; 
      $gccount{$lgene}++; 
      $pccount{$lprot}++; 
      # print "$1" if($debug); 
      # print "$2" if ($debug); 

       print OUT "$pepseq,$1,$2\n"; 
       } 
      } 
    } 

    my $ngenes = keys %gccount; 
    my $nprots = keys %pccount; 

某種程度上該肽不在輸出列表中。請幫助指出我哪裏出錯?

感謝

+1

兩件事情:1,始終包括'使用strict'和'使用warnings'每一個腳本的頂部,2.你有點['chomp'](http://perldoc.perl.org/functions/chomp.html) - 很高興。 –

+1

你能編輯你的帖子來修正你的代碼的格式嗎?首先,我認爲你的評論分爲三行。其次,如果您使用一致的縮進,每個人(包括您)都會發現您的代碼更容易閱讀。 –

回答

0

next if $_ !=~ "##";必須是如果你想跳過包含##隨時隨地他們行next if $_ =~ "##";

忽略這個謊言,如果$_匹配##

1

next if /##/; 

如果您只想跳過s與##

next if /^##/; 

如果你總是想跳過前兩行,而不管內容:

next if $. < 3;