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

Re: perl one liner to replace matching string (updated x2)

by haukex (Bishop)
on Jun 10, 2018 at 10:18 UTC ( #1216313=note: print w/replies, xml ) Need Help??

in reply to perl one liner to replace matching string

qx("perl -p -i -e \"s/(\@Filetyp\\s*?:)/\\1$ext/\" /path/test.c")

It is extremely rare that you need to call another perl from inside a Perl script! I'm going to guess that you're doing it for the effect of the -i flag? You can get that feature from inside Perl using $^I:

{ # new scope for local local *ARGV; @ARGV = '/path/test.c'; local $^I = ""; # -i command line switch while (<>) { s/(\@Filetyp\s*?:)/$1 c/; print; } }

Update: qx// is often problematic anyway!

Update 2: Fixed this potential issue in the above example code.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1216313]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2022-01-18 17:36 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (53 votes). Check out past polls.