Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by haukex (Chancellor)
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 = '/path/test.c'; local $^I = ""; # -i command line switch while (<>) { s/(\@Filetyp\s*?:)/$1 c/; print; } }

Update: qx// is often problematic anyway!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2019-09-22 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (273 votes). Check out past polls.

    Notices?