Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Substitution replacement not terminated

by shan_emails (Beadle)
on Sep 24, 2013 at 12:59 UTC ( [id://1055482]=perlquestion: print w/replies, xml ) Need Help??

shan_emails has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I have the perl file and that contents are

||/home/xx> cat test.pl #!/usr/bin/perl -w use strict; `perl -p -i -e 's/^(.{10})(.{382})(.*)$/$1^$2^$3/' test.txt`;
and when i run the file i got the below error
||/home/xx> perl test.pl Use of uninitialized value in concatenation (.) or string at test.pl l +ine 3. Use of uninitialized value in concatenation (.) or string at test.pl l +ine 3. Use of uninitialized value in concatenation (.) or string at test.pl l +ine 3. Substitution replacement not terminated at -e line 2.
But when i run this command in terminal it gives correct output and don't show any error
||/home/xx> perl -p -i -e 's/^(.{10})(.{382})(.*)$/$1^$2^$3/' test.txt ||/home/xx>
Shall i know what will be the solution for this.

Thanks in advance,
Shanmugam

Replies are listed 'Best First'.
Re: Substitution replacement not terminated
by choroba (Cardinal) on Sep 24, 2013 at 13:06 UTC
    Backquotes interpolate variables the same way as double quotes. Backslash the dollar signs.

    BTW: Why do you run perl from perl? You can do the work inside the script, as well (untested):

    open my $IN, '<', 'text.txt' or die $!; open my $OUT, '>', 'text.new' or die $!; while (<$IN>) { s/^(.{10})(.{382})(.*)$/$1^$2^$3/; print $OUT, $_; } close $OUT or die $!; rename 'text.new', 'text.txt';
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Substitution replacement not terminated
by johngg (Canon) on Sep 24, 2013 at 13:50 UTC

    You can supply the -p and -i flags within the script itself. Given that your offsets are fixed, you might find that substr is better suited. It is important to insert at your offsets working from the right.

    $ cat > spw1055482.txt aaaaaGGGGGG55555 fffffJJJJJJ11111 kkkkkUUUUUU99999 $ head -99 spw1055482.* aaaaaGGGGGG55555 fffffJJJJJJ11111 kkkkkUUUUUU99999 $ cat > spw1055482 #!/usr/bin/perl -npi.bak # use strict; use warnings; for my $offset ( 11, 5 ) { substr $_, $offset, 0, q{^}; } $ perl spw1055482 spw1055482.txt $ head -99 spw1055482* ==> spw1055482 <== #!/usr/bin/perl -npi.bak # use strict; use warnings; for my $offset ( 11, 5 ) { substr $_, $offset, 0, q{^}; } ==> spw1055482.txt <== aaaaa^GGGGGG^55555 fffff^JJJJJJ^11111 kkkkk^UUUUUU^99999 ==> spw1055482.txt.bak <== aaaaaGGGGGG55555 fffffJJJJJJ11111 kkkkkUUUUUU99999 $

    I hope this is helpful.

    Cheers,

    JohnGG

      Greate, Thanks for your help John.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1055482]
Approved by hdb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-28 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found