perl : unmatched ) in regex error

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

Answers


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

You are likely pasting in characters which are interpreted by the terminal software, hiding the command you actually ran.

For example,

$ 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.

Need Your Help

Custom Fonts for non-English Text

iphone objective-c xcode ipad uifont

I installed a custom font however, my app runs on two languages. I noticed that the custom fonts work with English but not with non-English. How can I overcome this?

jQuery Validation Engine not working

javascript jquery html5 validation

Trying to use the jQuery validation engine for 1 text field. For some reason It's not doing anything. I don't any errors to work off. If anyone see's something missing or out of place, I'd appreciate

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.