in reply to When <> fails

While I think that suggestions by pc88mxer and betterworld are the way to go, I can't help but wonder about the philosophical aspects of the issue :)

All scripts make certain base assumptions in order to function. A stable filesystem to act on is a good base assumption. If NFS is erratic, there's not much the script can do in terms of handling that kind of catastrophic failure. The partial damage would have already occurred in previous while (<>) iterations, anyway.

So, would it be useful to put out a warning that an unexpected critical error has just happened? Yes, that would be nice. But how far do we go?

Will this succeed as a new Perl idiom:
while (<>) { unless ($!) { # do actual stuff here } }
How far do we go down the path of paranoia just to make the script bullet-proof?

Update: Thanks for pointing my mistake out, ikegami. Still, I'd like to know how much is too much when it comes to error checking of this nature.

Replies are listed 'Best First'.
Re^2: When <> fails
by ikegami (Patriarch) on Jul 30, 2008 at 01:39 UTC

    That snippet makes no sense.

    • <> returns undef on error, so checking for an error in the loop is nonsense.
    • A true $! doesn't mean an error occured.
    • A false $! doesn't mean no error occured.