in reply to Re: no reaction on string replace
in thread no reaction on string replace

Hi, ok I was bit early ecouraged. the line  perl -pi.bak -e "s/test/replace/g;" filename.txt works as DOS command. But when I try to squeez it in my skript he needs an operator before the file path. So
#!/usr/bin/perl -w perl -pi.bak -e "s/test/replace/g;" C:/user/Desktop/filename.txt
is not working. Can you help me out, again? Thank you!

Replies are listed 'Best First'.
Re^3: no reaction on string replace
by Laurent_R (Canon) on Sep 11, 2013 at 21:26 UTC

    Yeah, on the DOS or UNIX command line, the "-pi.bak -e" options have the effect of considerably simplifying the syntax for modifying a text file.

    If you want to write a real script, it is slightly more complicated, those simplifications no longer apply.

    Within a Perl script, you would need to do something like this;

    #!/usr/bin/perl; use strict; use warnings; my $file_in = shift; open my $FH, "<", $file_in or die "cannot open $file_in $!"; while (<$FH>) { s/test/replace/g; print; }

    The above might still be considered simplistic, it is just giving an idea. Please don't hesitate to ask if you need further information.