Open p5pRT opened 12 years ago
Observe:
perl -E 'say eof STDOUT\, 2'
This outputs a "1" without the "2" and without a newline.
Actually\, this is two bugs\, though they're rather linked: eof() tries to read from the filehandle to determine if it's at EOF\, which sets the error flag if the handle is unreadable. print checks the error flag *after* every element is written\, and stops writing if it is set. Hence only the first element will be written.
To fix the first bug\, I suggest not trying to read from a write-only filehandle but always return true.
To fix the second bug (printing one element but not the rest)\, I suggest testing for errors before printing.
On Thu Jan 12 17:36:22 2012\, LeonT wrote:
This is a bug report for perl from fawaka@gmail.com\, generated with the help of perlbug 1.39 running under perl 5.14.2.
----------------------------------------------------------------- [Please describe your issue here]
Observe:
perl -E 'say eof STDOUT\, 2'
This outputs a "1" without the "2" and without a newline.
Actually\, this is two bugs\, though they're rather linked: eof() tries to read from the filehandle to determine if it's at EOF\, which sets the error flag if the handle is unreadable. print checks the error flag *after* every element is written\, and stops writing if it is set. Hence only the first element will be written.
To fix the first bug\, I suggest not trying to read from a write-only filehandle but always return true.
To fix the second bug (printing one element but not the rest)\, I suggest testing for errors before printing.
What a coincidence! Just today I discovered a similar bug with -T STDOUT. It causes print("foo"\,"bar") only to print "foo"; "bar" and $\ are not printed.
--
Father Chrysostomos
The RT System itself - Status changed from 'new' to 'open'
On Fri\, Jan 13\, 2012 at 3:10 AM\, Father Chrysostomos via RT \perlbug\-followup@​perl\.org wrote:
What a coincidence! Â Just today I discovered a similar bug with -T STDOUT. Â It causes print("foo"\,"bar") only to print "foo"; "bar" and $\ are not printed.
And possibly there are more issues like that. We should either decide to avoid reading from write-only handles\, or not set the error flag when someone does that. Or probably both.
Leon
On Sun Jan 15 08:05:08 2012\, LeonT wrote:
On Fri\, Jan 13\, 2012 at 3:10 AM\, Father Chrysostomos via RT \perlbug\-followup@​perl\.org wrote:
What a coincidence! �Just today I discovered a similar bug with -T STDOUT. �It causes print("foo"\,"bar") only to print "foo"; "bar" and $\ are not printed.
And possibly there are more issues like that. We should either decide to avoid reading from write-only handles\, or not set the error flag when someone does that. Or probably both.
I wonder why readline doesnât do that:
$ perl -le' \
--
Father Chrysostomos
On Sun\, Jan 15\, 2012 at 8:15 PM\, Father Chrysostomos via RT \perlbug\-followup@​perl\.org wrote:
I wonder why readline doesnât do that:
$ perl -le' \
; print "a"\,"b"' ab
Because readline for some reason I do not quite understand\, seems to clear the error flag. See pp_hot.c:1671. Doing a read on it does show exactly this behavior though\, as one would expect:
perl -le' read STDOUT\, my $foo\, 1; print "a"\,"b"'
It's a mess\, really.
Leon
On Sun Jan 15 11:42:34 2012\, LeonT wrote:
On Sun\, Jan 15\, 2012 at 8:15 PM\, Father Chrysostomos via RT \perlbug\-followup@​perl\.org wrote:
I wonder why readline doesnât do that:
$ perl -le' \
; print "a"\,"b"' ab Because readline for some reason I do not quite understand\, seems to clear the error flag. See pp_hot.c:1671. Doing a read on it does show exactly this behavior though\, as one would expect:
perl -le' read STDOUT\, my $foo\, 1; print "a"\,"b"'
It's a mess\, really.
That suggests to me that print should just ignore the error flag and print anyway. After all\, the error could be for any number of reasons.
Or it could check the error status before printing (is the actual errno number stored with the filehandle?) and see whether it changes after that\, bailing out if it has changed.
--
Father Chrysostomos
Migrated from rt.perl.org#108124 (status was 'open')
Searchable as RT108124$