in reply to Sort Large Files
I am also a little curious if they generate the same output. My version should preserve the order when two or more dates are the same. For anyone interested in micro-optimization, unpack 'x6A4X10A2xA2', $field[4] might be faster than the split/slice combo but is untested.#!/usr/bin/perl use warnings; use strict; my $file = $ARGV[0] || 'bigfile.dat'; open (INPUT, '<', $file) or die "Unable to open $file for reading : $! +"; my %date; my $pos = tell INPUT; while ( <INPUT> ) { my @field = split /\|/; push @{ $date{ join '', (split m|/|, $field[4])[2,0,1] } }, $pos; $pos = tell INPUT; } for ( sort { $a <=> $b } keys %date ) { for ( @{ $date{ $_ } } ) { seek INPUT, $_, 0; print scalar <INPUT>; } }
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort Large Files
by Velaki (Chaplain) on Jan 06, 2005 at 01:20 UTC |