develooper Front page | perl.perl5.porters | Postings from August 2008

Re: Near-FMTEYEWTK instructorial on ties, handles, and methods (was: How to tell whether readline got an error or EOF)

Thread Next
From:
Tom Christiansen
Date:
August 3, 2008 15:02
Subject:
Re: Near-FMTEYEWTK instructorial on ties, handles, and methods (was: How to tell whether readline got an error or EOF)
Message ID:
5511.1217800913@chthon
>> (1)                     TIEHANDLE, 
>> 
>> (2)                     at least one of PRINT, 
>>                                         PRINTF, 
>>                                         WRITE,

>Note that this is the method to support syswrite, not the write that is
>used for format. The latter is sadly not yet supported.

Good point.  I guess that would have to intercept the nearly-unused
formline() builtin.  I did mention it perlform, because I think it's
useful to have a different calling convention for formats.

   Or to make an swrite() subroutine, which is to write()
   what sprintf() is to printf(), do this:

       use Carp;
       sub swrite {
           croak "usage: swrite PICTURE ARGS" unless @_;
           my $format = shift;
           $^A = "";
           formline($format,@_);
           return $^A;
       }

       $string = swrite(<<'END', 1, 2, 3);
    Check me out
    @<<<  @|||  @>>>
    END
       print $string;

However, IO::Handle supports all of 3 of:

    $io->format_write( [FORMAT_NAME] )
    $io->syswrite ( BUF, [LEN, [OFFSET]] )
    $io->write ( BUF, LEN [, OFFSET ] )

syswrite is/was C's read(2) syscall, while write here is the opposite of
Perl's read.  As that was once C's fread(3S) libc call, I guess ->write was
C's fwrite(3S), not its write(2) syscall.  

I don't think that once-eludidating necessarily translates well, or like
that, for systems using PerlIO, though.

--tom

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