msalerno has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use Date::Calc qw(Mktime Today_and_Now Delta_DHMS); my @starttime = Today_and_Now; open (BIGLOG, "< E:/biglog.log") || die "Cannot open log\n"; my $offsets = pack 'I', 0; $offsets .= pack 'I', 0; while (<BIGLOG>){ $offsets .= pack 'V', tell BIGLOG; if ($_ =~ /^\s*#/ || $_ =~ /^\s\n/ || $_ !~ /^\s*\d/ ){ $offsets .= pack 'V', 0; } else{ $offsets .= pack 'V', Mktime(unpack("A4xA2xA2xA2xA2xA2", $_)); } } my @endindex = Today_and_Now; print "\nIndexed ". (length($offsets)/8 -1)." Lines in "; printf("%02d Days, %02d Hours, %02d Minutes, %02d Seconds", Delta_DHMS +(@starttime, @endindex)); # EPOCH = ($_ - 1) * 8 + 4; # BYTE = ($_ - 1) * 8; ## # # Sort # ## my @endtime = Today_and_Now; print "\nTotal runtime:\t\t"; printf("%02d Days, %02d Hours, %02d Minutes, %02d Seconds\n", Delta_DH +MS(@starttime, @endtime)); close BIGLOG; exit; sub readline_n{ my( $fh, $line) = @_; seek $fh, unpack( 'V', substr( $offsets, ($line - 1) * 8, 4 )), 0; scalar <$fh> }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort big text file - byte offset - 50% there (Added code)
by BrowserUk (Patriarch) on Aug 11, 2006 at 20:02 UTC | |
by msalerno (Beadle) on Aug 11, 2006 at 21:31 UTC | |
by BrowserUk (Patriarch) on Aug 11, 2006 at 21:55 UTC | |
by msalerno (Beadle) on Aug 14, 2006 at 15:13 UTC | |
by BrowserUk (Patriarch) on Aug 14, 2006 at 15:32 UTC | |
| |
by msalerno (Beadle) on Aug 11, 2006 at 21:41 UTC | |
by tye (Sage) on Aug 11, 2006 at 21:56 UTC |