in reply to Best way to handle readline errors?

If you can live with the file getting closed,

while (<$fh>) { ... } close($fh) or die("Error reading from input file: $!\n");

Or does that only work for output files?

Replies are listed 'Best First'.
Re^2: Best way to handle readline errors?
by jrw (Monk) on Nov 11, 2006 at 01:16 UTC
    The doc says "Closes the file or pipe associated with the file handle, returning true only if IO buffers are successfully flushed and closes the system file descriptor. Closes the currently selected filehandle if the argument is omitted."

    So, I don't think that will work for input files.

      I just confirmed through testing that close doesn't return an error (on Windows, using Perl 5.8.8). Sorry, I didn't have a chance to test it earlier.