Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: reg perl substitution

by mwah (Hermit)
on Nov 09, 2007 at 19:17 UTC ( [id://649978]=note: print w/replies, xml ) Need Help??


in reply to reg perl substitution

hen i print the line the value is changed but when i vi the file it still has the old value..any help of what's going wrong

As moritz said, you are just "reading" a file. Thats it. BUT: Perl provides a special way to modify lines of files via its command line interface. The following command would read the file line by line and change the sequence "newyork 1536000" to the desired output - which is written to a temporary file and renamed to the original file name afterwards. The original file will be kept and named test.cfg.bak (this is what the -i option does).

Unix/Linux: perl -i.bak -pe 's/(newyork\s+)1536000/${1}7878787878/' test.cfg Windows: perl -i.bak -pe "s/(newyork\s+)1536000/${1}7878787878/" test.cfg

Regards

mwa

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found