in reply to Detecting write errors (disk full, bad media)

When you have a question about a function built into Perl, reading the documentation that comes with Perl for that function usually helps.

> perldoc -f print Prints a string or a list of strings. Returns true if successful. ...

So, if the print function does not return a true value, an error happened. Also see perlvar on $!.

Replies are listed 'Best First'.
Re^2: Detecting write errors (disk full, bad media)
by bart (Canon) on Jul 01, 2011 at 12:39 UTC
    But who in the world checks the return value of print? Nobody, I guess, unless autodie handles it, if it can...

    I think a safer bet is to explicitly close the output filehandle and check its return value. Or, again, rely on autodie.

      Re. >>who in the world checks the return value of print?<< ... for the record, I do, IF it's writing a file likely to get very large. I didn't used to, then lost several hours of my life debugging strange behaviour in a production script which had worked fine for many months. The cause was a full disk, but the relevant print statements failed silently (even using strict and warnings) and the script happily ran to completion.