Open p5pRT opened 22 years ago
write() on a tie()d filehandle complains about an unopened filehandle.
The printf() on the that same tie()d filehandle works ok.
I looked at the documentation but couldn't find any mention of write() not beeing supported.
This program demonstrates it (confirmed for ActivePerl 5.6.1 build 628).
#!perl
use warnings FATAL => 'all';
use strict;
{
package FakeOut;
sub TIEHANDLE { bless \( my $scalar ), shift; }
sub PRINT { my $self = shift; $$self .= shift; }
sub PRINTF {
my $self = shift;
my $fmt = shift;
$$self .= sprintf $fmt, @_;
}
}
my( $text, $numb );
format FAKEOUT =
@<<<<<<<<<< @>>>>>
$text, $numb
.
my $fake = tie *FAKEOUT, 'FakeOut';
foreach $text ( qw( one two three four five ) ) {
$numb = length $text;
# printf FAKEOUT "%-10s %5s\n", $text, $numb;
write FAKEOUT;
}
print $$fake;
__END__
write() on unopened filehandle FAKEOUT at tiedwrite.pl line 27.
still present in bleed@20710
Is this a bug? Wouldn't you have to define a WRITE method for the tied handle for this to work?
--hugmeir
WRITE is for syswrite. If WRITE were for formats\, then WRITE would have to implement formats itself\, which would not be very helpful.
Currently write() simply ignores the tiedness\, just like stat (#112164).
And I’ve just discovered that printf won’t fall back to PRINT if PRINTF is not defined\, which is not very nice.
I’m now wondering whether tied filehandles could be implemented as an IO layer instead. Then a lot of these things could Just Work. But I may be drawing that conclusion prematurely.
--
Father Chrysostomos
On Sat\, 26 May 2012 17:48:04 -0700\, "Father Chrysostomos via RT" \perlbug\-followup@​perl\.org wrote:
WRITE is for syswrite. If WRITE were for formats\, then WRITE would have to implement formats itself\, which would not be very helpful.
WRITE is for syswrite\, write is for write. confusing and heavyly underdocumented
@Tux should this be closed?
Migrated from rt.perl.org#8149 (status was 'open')
Searchable as RT8149$