Thank you very much. I was so focused on getting the pack and sort working correctly that I completely overlooked that loop.
For anyone who might be interested in doing something similar in the future, here is a stripped down version that works.
Once again, thanks everyone.
#!/usr/bin/perl -w
use strict;
use Date::Calc qw(Mktime);
open (BIGLOG, "< D:/Logs/biglog.unsorted.log")
|| die "Cannot open unsorted log $!";
my( $offset, @index ) = 0;
while (<BIGLOG>){
my $epoch = ( /^\s*#/ or /^\s\n/ or $_ !~ /^\s*\d/ )
? 0
: Mktime( unpack 'A4xA2xA2xA2xA2xA2', $_ );
push @index, pack 'NN', $epoch, $offset;
$offset = tell BIGLOG;
}
@index = sort {$a cmp $b} @index;
open (OUTFILE, "> D:/Logs/biglog.sorted.log") || die "Cannot write sor
+ted log $!";
while (@index){
print OUTFILE readline_n(\*BIGLOG, shift @index);
}
close BIGLOG;
close OUTFILE;
exit;
sub readline_n{
my( $fh, $line) = @_;
seek ($fh, unpack( 'N',substr( $line, 4, 4 )), 0) || warn "Problem
+ seeking to $line $!\n";
scalar <$fh>
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.