Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: using s///g;

by taiko (Sexton)
on Aug 06, 2015 at 11:38 UTC ( [id://1137656]=note: print w/replies, xml ) Need Help??


in reply to using s///g;

Try this It will save the "old" file to file with *.old as an extension and new file with original name with your modifications
local $^I = '.old'; local @ARGV = ( 'your_file_name' ); my $find = "20150518"; my $replace = "18 May 2015"; while ( <>){ s/$find/$replace/g; print; }

Replies are listed 'Best First'.
Re^2: using s///g;
by ravi45722 (Pilgrim) on Aug 06, 2015 at 11:51 UTC
    Is it possible to change the data without changing extension, name & path of the file????
      Nope, you essentially can't change a free-format sequential file like that. That's why, behind the scene, you have to rename your original file (say into file.old), and then write your changed content to a new file having the name of your original file.

      The alternative is to read the whole file into memory, make the changes in memory and then clobber the content of the original file and write the new content to it.

      The modified file will have same extension and name as original file
      Original/unmodified file will get new extension *.old.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found