in reply to Re^3: Sort big text file - byte offset - 50% there (Added code)
in thread Sort big text file - byte offset - 50% there
One more question, it's about vec. I have not been able to find any good guides on using it. If I implemented it, would I be able to reduce my memory footprint? Does anyone have a good link with a explanation of the function? Something like perlpacktut but for vec? Thanks again. Here is the updated script with the new sort and old warning.
#!/usr/bin/perl -w use strict; use Date::Calc qw(Mktime Today_and_Now Delta_DHMS); my @starttime = Today_and_Now; print "Begin Index\n"; open (BIGLOG, "< D:/Logs/biglog.unsorted.log") || die "Cannot open log\n"; my @index; while (<BIGLOG>){ my $offset = tell BIGLOG; my $epoch = ( /^\s*#/ or /^\s\n/ or $_ !~ /^\s*\d/ ) ? 0 : Mktime( unpack 'A4xA2xA2xA2xA2xA2', $_ ); push @index, pack 'NN', $epoch, $offset; } print "\nIndexed ". @index ." Lines in "; printf "%02d Days, %02d Hours, %02d Minutes, %02d Seconds\n", Delta_DH +MS( @starttime, Today_and_Now ); print "Begin Sort\n"; my @startsort = Today_and_Now; @index = sort {$a cmp $b} @index; print "Sorted ". @index ." Lines in "; printf "%02d Days, %02d Hours, %02d Minutes, %02d Seconds\n", Delta_DH +MS( @startsort, Today_and_Now ); open (OUTFILE, "> D:/Logs/biglog.sorted.log") || die; foreach (@index){ my $byte = unpack( 'N',substr( $_, 4, 4 )); print OUTFILE readline_n(\*BIGLOG, $byte ) || warn unpack( 'N', substr( $_, 0, 4 )).":".unpack( 'N',substr( +$_, 4, 4 )).$!; } close OUTFILE; close BIGLOG; print "\nTotal runtime:\t\t"; printf "%02d Days, %02d Hours, %02d Minutes, %02d Seconds\n", Delta_DH +MS( @starttime, Today_and_Now); exit; sub readline_n{ my( $fh, $line) = @_; seek $fh, $line, 0; scalar <$fh> }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Sort big text file - byte offset - 50% there (Added code)
by BrowserUk (Patriarch) on Aug 14, 2006 at 15:32 UTC | |
by msalerno (Beadle) on Aug 14, 2006 at 16:03 UTC | |
by BrowserUk (Patriarch) on Aug 14, 2006 at 20:22 UTC | |
by msalerno (Beadle) on Aug 14, 2006 at 21:13 UTC | |
by msalerno (Beadle) on Aug 31, 2006 at 21:05 UTC | |
|