[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Getting *last* line of info from file



In Regards to your letter <v02130503add4b68bd674@DialupEudora>:
> >while (<IN>) {
> >  if ($_ eq "") {
> >    @MyArrayValue = splice(/|/,$_);
> >    }
> >  }
> >
> >or thereabout..  I am not sure about the splice command again.  fields are
> >separated by a  |  char, and lines separated by a  \n  character.
> 
> Yep.  You don't want splice, you want split:
> 
>     $lastLine = $_ while( $_ = <IN> );
>     @MyArrayValue = split( /|/, $lastLine );

As for getting to the end of your file _quickly_, if you know
the maximum length of a line (say its L), then you can use
seek() to shorten the reading:

        ( ... $length ... ) = stat();
        $pos = $lenth - (2 * L); # you _could_ just use (L + 1)
        $pos = if ( $pos < 0 );
        seek( $pos );
        while( <IN> )
                {
                ...
                }

That code is "psuedo-code" you know.


tim.

time@ice.com     <http://www.ice.com/>

USENET - a slow moving self parody... ph