This is exactly what the code I posted on this thread performed. Although, I
took more liberties figuring that it is very quick to read MAXSIZE bytes of
a text file into an array of @lines and just indexing the last line via
$line[-1] . I chose MAXSIZE of 512, but it can be adjusted. Trivial to read
512 bytes into an array of lines both in terms of speed and memory.

--
Mike Arms


-----Original Message-----
From: Samuel [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 22, 2002 8:36 PM
To: Activeperl (E-mail)
Subject: Re: Last Element of Array


Let's assume that MAXSIZE is the maximum size of a line, including
carriage-return and line-feed and such for the last line and the prior line.

Using the Windows SDK it is possible to open a file then do either one of
the following:

    � Seek to the end of the file then seek backwards MAXSIZE bytes

    � Seek to MAXSIZE bytes prior to the end of the file

Then it should be possible to search the data backwards from the end to find
the carriage-return and line-feed of the second to the last line. Then you
know where the last line begins. I do not know the details of how to do that
in Perl but it should be possible.


----- Original Message -----
From: "Richard Fisher" <[EMAIL PROTECTED]>
To: "Activeperl (E-mail)" <[EMAIL PROTECTED]>
Sent: Friday, March 22, 2002 1:50 PM
Subject: Last Element of Array


> HI all,
>
> I am opening a very large log file and I am wondering if there is a better
> way of retriving the last line of that log file that the one I have below.
> I just seems to be a waste opening such a large file if I don't have to
open
> the whole file. i.e. does open have a way of opening up a partial file or
> just specific lines of a file in my case the last line?
>
> Thanks
>
> use strict;
>
>    my (@logcontents, $status_line);
>   open BUILDLOG, "my_file";
> chomp(@logcontents = (<BUILDLOG>));
>   $status_line = $#logcontents;
>       print "The last line of the log file is
@logcontents[$status_line]\n";
>
>
>
> Richard Fisher
> Software Configuration Management Specialist
> Optiwave Corporation
> 7 Capella Court
> Ottawa, Ontario
> Canada K2E 7X1
> Tel: (613) 224-4700
> Fax:(613) 224-4706
> Visit us on the web at : http://www.optiwave.com
>
>
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to