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.
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.