-3

I'm no perl programmer, so I just need this simple script to run:

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

the error is: Unmatched ) in regex; marked by <-- HERE in m/^(\d+)\s+(\d+) <-- HERE / at -e line 1.

Anyone knows how to fix it?

Thank you in advance!

TP

4

2 回答 2

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.
于 2013-05-02T23:49:33.717 回答
1

This program looks rather better laid out properly as a script. With use strict and use warnings it's fine:

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";
}

Run it as

perl script.pl > dnaplotter.plot
于 2013-05-03T01:14:56.093 回答