Next | Welcome to my ~/bin | 141 |
Here's what I should have done:
unless (open IN, "< $file") { warn "Couldn't open file `$file' for reading: $!; skipping.\n"; next; } unless (rename $file, "$file.$$.tmp") { warn "Couldn't rename file `$file': $!; skipping.\n"; next; } unless (open OUT, "> $file") { warn "Couldn't open file `$file' for writing: $!; skipping.\n"; rename "$file.$$.tmp", $file or die "Couldn't restore $file.$$.tmp to $file: $!; ABORTING";
} ... unlink "$file.$$.tmp";
I suppose it would have been cleverer to use Perl's -i.bak feature:
local $^I = ""; while (<>) { ... }
I wish I had thought of it at the time
Next | Menu | Copyright © 2005 M. J. Dominus |