ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl6-language
perl6-language
Re: Custom iterators
by Michael G Schwern other posts by this author
Sep 25 2001 5:22PM messages near this date
Re: Custom iterators | RE: Custom iterators
On Tue, Sep 25, 2001 at 12:59:51PM -0400, Uri Guttman wrote:
>  >>>>> "MGS" == Michael G Schwern <schwern@[...].com> writes:

>  

>    MGS> Backwards?

>  

>    MGS>     File.read_backwards($filename) {

>    MGS>         print

>    MGS>     }

>  

>  not trivial but not too hard. check out File::ReadBackwards for a way to

>  do it efficiently in perl5. it requires some careful seeking, buffering

>  and scanning for the line endings. it probably should be a module and

>  not core. it could be combined with a bunch of other useful file or file

>  iterators classes.


The details of the implementation are irrelevent (in fact, the guts
will probably be nearly the same as File::ReadBackwards).  The point
is, instead of the interface being this:

    use File::ReadBackwards;
    $bw = File::ReadBackwards-> new( 'log_file' ) or

                              die "can't read 'log_file' $!" ;

    while( defined( $log_line = $bw-> readline ) ) {

        print $log_line ;
    }

or this:

    use File::ReadBackwards;

    tie *BW, File::ReadBackwards, 'log_file' or
                              die "can't read 'log_file' $!" ;

     while( <BW>  ) {

         print ;
     }

it can be this:

    File.read_backwards('log_file') {
        print;
    }

Ta da!


-- 

Michael G. Schwern   <schwern@[...].com>     http://www.pobox.com/~schwern/

Perl6 Quality Assurance     <perl-qa@[...].org> 	     Kwalitee Is Job One

<Skrewtape>  I've heard that semen tastes different depending on diet.  Is that

	    true?
<Skrewtape>  Hello?

<Schwern>  Skrewtape:  Hang on, I'm conducting research.



Thread:
Michael G Schwern
Piers Cawley
Michael G Schwern
Bart Lateur
Michael G Schwern
Bart Lateur
Michael G Schwern
Uri Guttman
Michael G Schwern
Brent Dax
Bryan C. Warnock
Michael G Schwern

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved