in reply to Lost in-place file edit code

You can achieve within a program the same effect as with the -i command line switch, by setting the perlvar $^I to the value of the backup extension. For example, the following snippet upper-cases the contents of the files foo.txt and bar.txt in place, and puts backup copies in foo.txt.bkp and bar.txt.bkp (note that there is no explicit open):

use strict; use warnings; $^I = q(.bkp); @ARGV = qw( foo.txt bar.txt ); print uc while <>; __END__
Setting $^I above to the empty string, causes foo.txt and bar.txt to be upper-cased in place, but no backups are created.

the lowliest monk

Replies are listed 'Best First'.
Re^2: Lost in-place file edit code
by GrandFather (Saint) on Jun 08, 2005 at 21:14 UTC
    Thank you. That was what I was looking for.

    Food for thought, not fuel for flames.