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

Re: tied filehandles do not honour write

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
April 2, 2007 14:01
Subject:
Re: tied filehandles do not honour write
Message ID:
b77c1dce0704021401qd68cb11ta93238caf08b8a12@mail.gmail.com
On 29/03/07, H.Merijn Brand <h.m.brand@xs4all.nl> wrote:
> On Mon, 5 Mar 2007 18:59:57 +0100, "H.Merijn Brand" <h.m.brand@xs4all.nl>
> 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 xx.pl
> #!./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
syswrite().

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About