Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.98k stars 559 forks source link

problem with write() and a tie()d filehandle #4762

Open p5pRT opened 22 years ago

p5pRT commented 22 years ago

Migrated from rt.perl.org#8149 (status was 'open')

Searchable as RT8149$

p5pRT commented 22 years ago

From abe@ztreet.demon.nl

Created by abe@ztreet.demon.nl

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.

Perl Info ``` Flags: category=core severity=low Site configuration information for perl v5.7.2: Configured by a.timmerman at Sat Dec 15 02:26:14 2001. Summary of my perl5 (revision 5 undef) configuration: Platform: osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread uname='' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef usethreads=undef use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=undef usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cl', ccflags ='-nologo -Gf -W3 -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX', optimize='-O1 -MD -DNDEBUG', cppflags='-DWIN32' ccversion='undef', gccversion='', gccosandvers='undef' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=4 alignbytes=8, prototype=define Linker and Libraries: ld='link', ldflags ='-nologo -nodefaultlib -release -libpath:"c:\opt\perl572\lib\CORE" -machine:x86' libpth=\lib libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib perllibs=undef libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl57.lib Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release -libpath:"c:\opt\perl572\lib\CORE" -machine:x86' Locally applied patches: DEVEL13686 @INC for perl v5.7.2: c:/opt/perl572/lib c:/opt/perl572/site/lib . Environment for perl v5.7.2: HOME (unset) LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=c:\opt\perl572\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\system32\WBEM;C:\Perl\bin\;C:\usr\bin\;C:\usr\bin;C:\bin;C:\usr\local\bin;c:\usr\local\openssl\bin;C:\gcc-2.95.2\bin;C:\PROGRA~1\ULTRAE~1;C:\Program Files\SecureCRT 3.0;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin PERLDOC_PAGER=less PERL_BADLANG (unset) SHELL (unset) groetje, Abe -- perl -wle '%_=qw(Just Just another Perl Perl another hacker hacker);print join" ",map$_{$_}=>sort keys%_' ```
p5pRT commented 21 years ago

From @iabyn

still present in bleed@​20710

p5pRT commented 12 years ago

From @Hugmeir

Is this a bug? Wouldn't you have to define a WRITE method for the tied handle for this to work?

--hugmeir

p5pRT commented 12 years ago

From @cpansprout

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

p5pRT commented 12 years ago

From @tux

On Sat\, 26 May 2012 17​:48​:04 -0700\, "Father Chrysostomos via RT" \perlbug\-followup@&#8203;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

toddr commented 4 years ago

@Tux should this be closed?