2013-05-02 62 views
-3

我不是Perl程序員,所以我只需要這個簡單的腳本來運行:的Perl:無與倫比)在正則表達式錯誤

perl -e 'open(FILE,"tmp.plot"); my $seqLength = 643292; my $count=1; while(my $ln = <FILE>){ if($ln =~ m/^(\d+)\s+(\d+)/) { if($1 > $count) { for($i = $count; $i < $1 
; $i++){ print "0\n" } }; print "$2\n"; $count=$1+1; } } for($i = $count; $i <= $seqLength; $i++){ print "0\n" }' > dnaplotter.plot 

的錯誤是: Unmatched) in regex; marked by <-- HERE in m/^(\d+)\s+(\d+) <-- HERE/at -e line 1.

任何人都知道如何解決它?

預先感謝您!

TP

+5

'-e'通常保留給單行。爲什麼不把它保存到一個腳本中並用'perl scriptname'運行它? – tadman 2013-05-02 23:14:52

+2

我沒有收到錯誤,也沒有看到錯誤。 – kjprice 2013-05-02 23:15:15

+1

在Perl 5.12.4上運行時,我不會收到錯誤。 – tadman 2013-05-02 23:17:10

回答

1

這個節目看起來相當好奠定了正確的腳本。隨着use strictuse warnings它的罰款:

use strict; 
use warnings; 

open(FILE, "tmp.plot") or die $!; 

my $seqLength = 643292; 
my $count  = 1; 

while (my $ln = <FILE>) { 
    if ($ln =~ m/^(\d+)\s+(\d+)/) { 
     if ($1 > $count) { 
      for (my $i = $count; $i < $1; $i++) { 
       print "0\n"; 
      } 
     } 
     print "$2\n"; 
     $count = $1 + 1; 
    } 
} 

for (my $i = $count; $i <= $seqLength; $i++) { 
    print "0\n"; 
} 

運行它

perl script.pl > dnaplotter.plot 
4

您在字符粘貼有可能被通過終端軟件解釋,躲在你居然跑的命令。

例如,

$ echo -e 'm/^(\\d+)\\s+(\\d+)\x08)/' | od -c 
0000000 m /^ ( \ d + ) \ s + ( \ d + ) 
0000020 \b ) /\n 
0000024 

# Note the extra Backspace and ")" in the od output. 

$ echo -e 'm/^(\\d+)\\s+(\\d+)\x08)/' 
m/^(\d+)\s+(\d+)/ 

$ echo -e 'm/^(\\d+)\\s+(\\d+)\x08)/' | perl -c 
Unmatched) in regex; marked by <-- HERE in m/^(\d+)\s+(\d+) <-- HERE/at - line 1.