Hi everybody,

I've done a dummy test, and finalized that David's method is the
Goal Method, that's really Really Very Great !!!

I've made a 50MB Text file ( Fixed length, 1001 char per line, with \n)
for this test, and have the following results :

#### SCRIPT 1 ##### Suggested by Johnson
$start = time;
open (FH, "text.txt");
while (<FH>) { $data = $_ }
close (FH);
$end = time - $start;
print $end."\n";
###### END WITH 8 SECs #######

##### SCRIPT 2 #### Suggested by myself
$start = time;
open (FH, "text.txt");
@FD = <FH>;
close (FH);
$data = $FD[$#FD];
$end = time - $start;
print $end."\n";
###### END WITH 8 SECs #######

##### SCRIPT 3 #####  Suggested by David ( I've completing it =))
$start = time;
open (FH, "text.txt");
seek (FH,0,2); ## I use 0 here as I assume the last line is not /^\n$/
$curpos = tell(FH);
while (! $PrevEOL)
{   $data = <FH>;
     if ($data !~ /\n$/) { $curpos -- ; seek (FH, $curpos, 0);  }
     else { $PrevEOL = 1 }
}
$data = <FH>; close (FH);
$end = time - $start;
print $end."\n";
###### END WITH 0 SEC ( Actually 0.0x Sec) #######

Please don't alarm me for omitted to use my , strict and -wT here,
I will use them for doing my own script =)

Besides, even though the time consume for Johnson's one and mine
one are the same (nearly), however, it's better for try Johnson's one.
That's beacuse if there are 5 or more clients query this File at the same
time, mine one will surely halt the system (WinMe).

Wish you have a nice day,
Smiley Connie =)



----- Original Message -----
From: "David vd Geer Inhuur tbv IPlib" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, June 24, 2002 7:35 PM
Subject: Re: Reading File


>
> I am try-ing to work something out with seek for you, but just can't find
it yet.
> This is how far I am yet :
>
> #!/usr/bin/perl
>
> use strict;
>
> my $file = "...";
>
> open(FH, "<$file");
> seek(FH,2,2);
> my $curpos = tell(FH); $_ = <FH>;
> my $lastline = <FH>;
> close(FH);
>
> print "$lastline \n";
> print "$curpos \n";
> # --------------
>
> As the seek brings me to the end of the file at the last character I cant
print
> the current line.
> I will be looking further, there must be a beatifull way to do this.
>
> Regs David
> ----------------
> >
> > open (FILE, "yourfile.txt");
> > my @FD = <FILE>;
> > close (FILE);
> >
> > my $lastline = $FD[$#FD]
> >
> > Hope this help,
> > Smiley Connie =)
> >
> >
> > ----- Original Message -----
> > From: "Karen Liew Ying Ping" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Monday, June 24, 2002 6:05 PM
> > Subject: Reading File
> >
> >
> > Hi,
> >
> > Let's say I'm opening a file.
> > How do I read the last line of the file?
> > is there any function in doing so?
> >
> > Thanks.
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to