Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Substitution replacement not terminated

by shan_emails (Beadle)
on Sep 24, 2013 at 12:59 UTC ( #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/iesadm/shan> 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/iesadm/shan> 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/iesadm/shan> perl -p -i -e 's/^(.{10})(.{382})(.*)$/$1^$2^$3/' + test.txt ||/home/iesadm/shan>
Shall i know what will be the solution for this.

Thanks in advance,
Shanmugam

Comment on Substitution replacement not terminated
Select or Download Code
Re: Substitution replacement not terminated
by choroba (Abbot) 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 (Abbot) 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
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? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-08-23 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls