in reply to Re: Sorting rows in a text file
in thread Sorting rows in a text file
So, I'll suggest using a Schwartzian Transform (an algorithm created by our very own merlyn).
untested code:
The basic speed eater for thinker's way is that you have to munge the date to sort it a great number of times.#!/usr/bin/perl -w use strict; open (DATA, "./data.txt") or die $!; # for example my @sorted = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { [ &fix_date($_), $_ ] } <DATA>; for (@sorted) { print $_ }; sub fix_date { my ($d,$m,$y) = ( shift =~ m|(\d\d)/(\d\d)/(\d{4})| ); return "$y-$m-$d"; }
The first (lower) map does the time expensive data munging, into a form that's easy for sort to deal with, and the last (top) map puts the data back into the original form
HTH
/\/\averick
perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"
|
|---|