Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^2: Extract new lines from log file

by smithers (Friar)
on Jan 05, 2007 at 21:49 UTC ( #593209=note: print w/replies, xml ) Need Help??

in reply to Re: Extract new lines from log file
in thread Extract new lines from log file

You are so right! SEEKing vs. line-by-line processing is wicked fast. For example script is a quick test script to determine timing to read the last 1024 bytes from the end of a 4GB file located on a remote server.

use strict; my $filename = shift; my ( $curpos, $charsread, $buffer ); open(LOGFILE, "<", $filename) or die "can't open file: $!"; # Read last 1024 bytes of data. Test this via # read to -1024 bytes from EOF. seek(LOGFILE, -1024, 2); $curpos = tell(LOGFILE); $charsread = read( LOGFILE, $buffer, 1024 ); print "Chars Read: $charsread\n"; print "Buffer: >$buffer<\n"; close(LOGFILE);

I ran as shown in next paragraph replacing my actual server name with "foo". I suspect most of you work with Perl on Unix but I'm loving Perl on Win32 and when I can use UNC file pathing as shown below it just tickles me that Perl is Win32 frienly in this way. Anyway, I digress. The result of below script run is the last 1024 bytes of the file is sub-second time. This is sooooooooooo fast! Thank you! \\foo\D$\MSSQL\BACKUP\DW\DW1_db_200701041904.BAK

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593209]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2023-12-06 17:42 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (31 votes). Check out past polls.