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

[perl #123158] print returns error when succeed

From:
Tony Cook via RT
Date:
November 13, 2014 04:29
Subject:
[perl #123158] print returns error when succeed
Message ID:
rt-4.0.18-22696-1415852972-923.123158-15-0@perl.org
On Sat Nov 08 11:13:33 2014, efimov@reg.ru 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";
    $f->clearerr;
  }

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.

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=123158



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About