in reply to Sort Large Files

Velaki,
In your description, you say the date is in the format MM/DD/YY, but in your code it looks like it is a 4 digit year. Out of idle curiosity, does the following run any faster?
#!/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>; } }
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.

Cheers - L~R

Replies are listed 'Best First'.
Re^2: Sort Large Files
by Velaki (Chaplain) on Jan 06, 2005 at 01:20 UTC

    Nifty! I'll give it a try! Elimitating the sprintf should speed it up. I just whipped it up adhoc in about 15 minutes to solve a quick problem. I like what you've done with it.

    Thanks!
    -v
    "Perl. There is no substitute."