Uri showed us his table driven tests in
http://search.cpan.org/src/URI/Sort-Maker-0.06/t/
and his buffered line-reader in
http://search.cpan.org/src/URI/File-ReadBackwards-1.04/ReadBackwards.pm

We hacked on Read Backwards to make a read-forwards, that is start for
non-OO inner inner thing for Ack new loop.

-
Bill
[EMAIL PROTECTED] [EMAIL PROTECTED]
==================
#! perl  -w

use strict;

my $n=0;

my $is_crlf = 0;
my $lines_ref = [ ] ; # will be static

while (defined( my $line = our_readline(\*STDIN)))
{

  print ++$n,q{: },$line;
}


# read the /p/r/e/v/i/o/u/s/ record from the file
#


sub our_readline {

        my( $handle) = @_ ;

        my $text ;

# get the buffer of lines


        return unless $lines_ref ;

        while( 1 ) {

# see if there is more than 1 line in the buffer

                if ( @{$lines_ref} > 1 ) {

# we have a complete line so return it
# and convert those damned cr/lf lines to \n

                        $lines_ref->[-1] =~ s/\015\012/\n/
                                        if $is_crlf; # @TBD

                        return( shift @{$lines_ref} ) ;
                }

# we don't have a complete, so have to read blocks until we do


# @TBD -- EOF

# we have to read more text so get the handle and the current read size

                my $read_size = 4096; # @TBD variable


# read in the next (previous) block of text

                $text = @$lines_ref ? pop @$lines_ref : "" ;
                my $read_cnt = sysread( $handle, $text, $read_size , length($tex
t) ) ;

                if ($read_cnt == 0) {
                        my $buf=shift @$lines_ref;
                        $lines_ref=undef;
                        return $buf;
                }
# split the buffer into a list of lines
# this may want to be $/
# assumes newline separators

                @{$lines_ref} =
                        $text =~ /(.*?\n|.+)/gs ;

#print "Lines \n=>", join( "<=\n=>", @{$lines_ref} ), "<=\n" ;

        }
}

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to