develooper Front page | perl.perl5.porters | Postings from April 2007

Re: tied filehandles do not honour write

Thread Previous | Thread Next
Rafael Garcia-Suarez
April 2, 2007 14:01
Re: tied filehandles do not honour write
Message ID:
On 29/03/07, H.Merijn Brand <> wrote:
> On Mon, 5 Mar 2007 18:59:57 +0100, "H.Merijn Brand" <>
> wrote:
> > OK, I know, nobody uses format/write, but still there is a syncing
> > problem in using write to a tied file handle, as I discovered while
> > preparing my DPWS talk. Somewhat cut-down example below.
> Also for PerlIO::via::scalar:
> nb09:/pro/3gl/CPAN/perl-current 76 > cat
> #!./perl -Ilib
> use strict;
> use warnings;
> format STDOUT =
> from format
> .
> my $stdout = "";
> open STDOUT, ">", \$stdout;

That's a red herring. For some reason this open fails. Replace STDOUT
by FOO and all works fine. That would be a bug in PerlIO::scalar.

However, concerning the original bug (with tied filehandles) : it
appears that you can provide methods for all printing primitives in a
tied filehandle class, except for write. You have PRINT, PRINTF, etc,
but no WRITE. Well, actually you do have WRITE... but it's for

So, the only way to solve this is to define a new kind of method, say
FMTWRITE, to be used when writing via a format. Does this sound
acceptable ? I don't know yet how to do it, the code to handle formats
is a bit complex.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About