develooper Front page | perl.beginners | Postings from April 2002

Re: Serious problem with perl -pi -e

Thread Previous | Thread Next
John W. Krahn
April 27, 2002 03:38
Re: Serious problem with perl -pi -e
Message ID:
Sharan wrote:
> Hello,


> I lost my files, while using perl -pi -e.
> I wanted to replace a world in a set of files, "perl -pi -e
> 's/somestring/somethingelse/g' *.pl"
> but, it gave error saying permission denied and all the files got deleted.
> If it cant rewrite the files, at least it should not delete.

Supply a string to the -i switch and perl will save the original file
with that string appended to the file name.  For example:

perl -pi.bak -s's/somestring/somethingelse/g' textfile.txt

Will save the original file as "textfile.txt.bak" and the modified file
as "textfile.txt"

use Perl;

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About