Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Edit File in place

by Bird (Pilgrim)
on Aug 13, 2002 at 14:31 UTC ( [id://189805]=note: print w/replies, xml ) Need Help??


in reply to Edit File in place

The -i command line switch allows for editing files in place. It also has the ability to back up the original file.

See perlrun

-Bird

Replies are listed 'Best First'.
Re: Re: Edit File in place
by spurperl (Priest) on Aug 14, 2002 at 06:13 UTC
    This is not quite what the OP asked. From perlrun:

    -i[extension] specifies that files processed by the `<>' construct are to be edited in-place. It does this by renaming the input file, opening the output file by the original name, and selecting that output file as the default for print() statements. The extension, if supplied, is used to modify the name of the old file to make a backup copy, following these rules:
    Meaning that -i basically does the same 'trick': open for read, edit, write back.
      This is not quite what the OP asked.

      How? The original post asked for a way to edit a file in place, which this is. This is not the same solution that the original post presented, because it does not entail reading the entire file into an array, then writing it back out. It allows for line by line editing, as well as giving an option for renaming the original. Even if this was the same solution as the original, it's a much more concise form of it, which means you could write a quick one-liner using this version, as opposed to writing out a whole script using the alternative.

      -Bird

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-16 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found