develooper Front page | perl.perl5.porters | Postings from November 2008

[perl #1154] Resent: write errors during -pi not handled

From:
Chip Salzenberg
Date:
November 17, 2008 12:01
Subject:
[perl #1154] Resent: write errors during -pi not handled
Message ID:
20081117200021.GP5495@tytlal.topaz.cx
{{ I filed this comment in RT and asked it to copy p5p, but over an hour
   later I don't see it.  I wonder what's up with that?  Meanwhile... }}

A first step in handling write errors in -pi would be dying if either print
or close returns false.  This would be a significant change from the old
ways, but I think it's OK ... data loss is one of the primary evils, after
all.

As for restoring the partially read file back to its original name on
error: I actually think that's a bad idea.  There may be a LOT of
processing involved, and partial output is definitely better than no
output in some circumstances.

Finally, adding death to the behavior of existing code that has its own
read/print loop is far more questionable, and I'd rather not do it.  In
other words, if you write this you should get death on disk full:

    perl -pi~ 's/foo/bar/' *.c

But if you write this you should _not_ get automatic death:

    #!/usr/bin/perl
    $^I = '~';
    while (<>) { ....; print }

Comments?
-- 
Chip Salzenberg <chip@pobox.com>



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About