Open p5pRT opened 17 years ago
This is a bug report for perl from clint@traveljury.com\, generated with the help of perlbug 1.35 running under perl v5.8.8.
-----------------------------------------------------------------
According to perlfunc\, if you try to re-open STDOUT or STDERR as an "in memory" file\, you have to close it first\, implying that if you want to re-open it to a file\, you DON'T need to close it first.
However\, if you don't close it first\, then the ':utf8' layer won't be applied:
#!/usr/bin/perl use strict; use warnings;
my $utf8="\xe9";
open STDOUT\, ">>:utf8"\, 'test.txt' or die $!; print "No close: "\,$utf8\,"\n";
close STDOUT; open STDOUT\, ">>:utf8"\, 'test.txt' or die $!; print "Close: "\,$utf8\,"\n";
PRINTS: No close: \xe9 (not literally - prints character \xe9\, not UTF-8 encoded) Close: é
On Thu\, 16 Aug 2007 13:15:15 GMT\, DrTech wrote:
This is a bug report for perl from clint@traveljury.com\, generated with the help of perlbug 1.35 running under perl v5.8.8.
-----------------------------------------------------------------
According to perlfunc\, if you try to re-open STDOUT or STDERR as an "in memory" file\, you have to close it first\, implying that if you want to re-open it to a file\, you DON'T need to close it first.
However\, if you don't close it first\, then the ':utf8' layer won't be applied:
#!/usr/bin/perl use strict; use warnings;
my $utf8="\xe9";
open STDOUT\, ">>:utf8"\, 'test.txt' or die $!; print "No close: "\,$utf8\,"\n";
close STDOUT; open STDOUT\, ">>:utf8"\, 'test.txt' or die $!; print "Close: "\,$utf8\,"\n";
PRINTS: No close: \xe9 (not literally - prints character \xe9\, not UTF- 8 encoded) Close: é
I'm confused by this report. You cite pod/perlfunc.pod with respect to opening in-memory files. The relevant documentation in perl-5.24.0 is this:
##### ... you can open filehandles directly to Perl scalars via:
open(my $fh\, ">"\, \$variable) || ..
To (re)open C\
close STDOUT; open(STDOUT\, ">"\, \$variable) or die "Can't open STDOUT: $!"; #####
So far\, so good. The example you provide\, however\, entails opening handles to regular files\, not in-memory files. If I rewrite your the first part of your example to print to a scalar reference (attached: print_to_scalar_no_close_first.pl)\, then I get an exception.
##### $ perl print_to_scalar_no_close_first.pl unable to open: Bad file descriptor at print_to_scalar_no_close_first.pl line 7. #####
If I close the filehandle first (attached as print_to_scalar_close_first.pl)\, I get reasonable results.
##### $ perl print_to_scalar_close_first.pl $VAR1 = 'Close: é '; #####
So I'm not sure if there is really a bug here. Thank you very much.
-- James E Keenan (jkeenan@cpan.org)
The RT System itself - Status changed from 'new' to 'open'
Migrated from rt.perl.org#44703 (status was 'open')
Searchable as RT44703$