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