Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: sed isn't working within a perl script

by Anonymous Monk
on Oct 19, 2012 at 09:17 UTC ( #999888=note: print w/replies, xml ) Need Help??


in reply to sed isn't working within a perl script

:D Calling sed from perl is like driving a bicycle inside a car -- just drive the car

The perl oneliner equivalent (as s2p helps me understand it)

perl -i -l -p -e ' s /(.*)/Number => ${1}/s; ' test.txt

But you still don't want to use system to run that oneliner

instead use

use File::Slurp qw/ edit_file /; edit_file { s /(.*)/Number => ${1}/s; } 'test.txt';

or some such

Replies are listed 'Best First'.
Re^2: sed isn't working within a perl script
by Anonymous Monk on Oct 19, 2012 at 09:42 UTC
    You want edit_file_lines because edit_file reads the whole file and not line-by-line
Re^2: sed isn't working within a perl script
by nvivek (Vicar) on Oct 19, 2012 at 10:37 UTC
    I don't want to include new module to do this stuff. That's why, I preferred system function with sed command. Reason is I am going to add this stuff in 1000 lines of code which does other operation.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2020-07-03 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?