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

[perl #123158] print returns error when succeed

Tony Cook via RT
November 13, 2014 04:29
[perl #123158] print returns error when succeed
Message ID:
On Sat Nov 08 11:13:33 2014, wrote:
> Then I run out of disk space. It stop printing. Then I free some disk
> space, it starts printing:
> ===
> Hey
> Error [No space left on device]
> Hey
> Error [No space left on device]

This happens because Perl_do_print()'s return value is based on the error state of the stream, not on the success or failure of the current operation.

This has been the case since at least 1994 (before PerlIO).

If you want to work with the current behaviour, you can clear the error state on each write failure, eg:

  unless (print $f "Hey\n") {
    print STDERR "Error [$!]\n";

There is a bug in that the documentation says that print returns true if the current operation succeeds, but that's incorrect.

I can see two possible fixes here:

1) update the documentation to print() to say it returns false if the stream is in an error state, or

2) modify Perl_do_print() to return false iff the current operation failed.


via perlbug:  queue: perl5 status: open Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About