in reply to Re: PerlIO::via FILL subroutine question
in thread PerlIO::via FILL subroutine question

Yeah, that's the gist of it (the rdw's are packed shorts, but that's a detail that doesn't matter). So, is there some way to implement readline so that I can provide perl with what my notion of a line is? At first, that's what I thought that FILL did, but I guess I was mistaken...

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

  • Comment on Re^2: PerlIO::via FILL subroutine question

Replies are listed 'Best First'.
Re^3: PerlIO::via FILL subroutine question
by Limbic~Region (Chancellor) on Oct 05, 2004 at 00:53 UTC
    thor,
    You can look at subclassing IO::File, but that is going to end up giving you a different OO interface. The other option is to tie the filehandle. I was disappointed that Tie::FileHandle::Base didn't do more in the way of giving you default methods to inherit. Here is a very rough proof of concept.
    package rdw; use Carp; sub TIEHANDLE { my ($class, $file) = @_; open ( my $file , '<', $file ) or croak "Unable to open $file : $! +"; return bless \$file , $class; } sub READLINE { my $self = shift; my ($length, $record); read $$self, $length, 1; return undef if eof $$self; read $$self, $record, $length; return $record; } 42; # and a script that uses it #!/usr/bin/perl use strict; use warnings; use rdw; tie *fh, 'rdw', 'foo.rdw' or die "Unable to tie : $!"; while ( <fh> ) { print "$_\n"; } __END__ # foo.rdw - outputs "a\nab\nabc\nabcd\n" as desired 1a2ab3abc4abcd
    See perldoc perltie for more information

    Cheers - L~R