in reply to Re: next if loop
in thread next if loop

You should check the return value of your close. It might fail.

What's the point? If the filehandle isn't going to close, there's not much you can do about it, except maybe complain about it to STDERR. I suppose you could try calling close again and pray that it will work this time, but if it failed the first time, it will probably fail again.

Is there really any use to catching errors from close?

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: next if loop
by Abigail-II (Bishop) on Nov 20, 2003 at 19:48 UTC
    I rather have a program that says "close failed: no space left on device" than a posting to perlmonks that say "I print to a file and it doesn't work".

    But that's just my personal preference.

    Abigail

Re: Re: Re: next if loop
by davido (Cardinal) on Nov 20, 2003 at 19:15 UTC
    Is there really any use to catching errors from close?

    I believe there is, when the file was opened for output. The output buffer may not be flushed until the close. If the close fails, it could be indicative of a failure to flush the buffer, and thus, the file output may be incomplete or otherwise corrupted. This can happen due to a number of reasons. Someone may have taken the floppy out of the drive prematurely, the HD may have filled up, the CD may not have burned properly, the dialup connection (on an open socket) may have terminated early, etc.

    In such an event, I would want to know about it, rather than have a silent failure.

    My habit is to always put the 'or die "$!\n";' after closing an output file. I don't worry too much about the success of closing an input file.


    Dave


    "If I had my life to live over again, I'd be a plumber." -- Albert Einstein