This code is by no means robust, but it should work if the data files are in _exactly_ the form you state.
Also, I am not sure whether 15/19/2001 means the 15th day of the 19th month, or vice versa. Whatever, that month is out of scale in my planet :-). So I assume dd/mm/yy
Oh, and it doesn't check the integrity of dates :-). Did I mention that.
Still, I hope the sort code can help you become familiar with how things work.
cheers#!/usr/bin/perl -w use strict; open DATA, "./data.txt"; # or wherever the file is my @data=<DATA>; my @sorted = sort sort_func @data ; for(@sorted){print $_}; sub sort_func{ my ($a_dd,$a_mm,$a_yy)=$a =~ m|(\d*)/(\d*)/(\d*)|; my ($b_dd,$b_mm,$b_yy)=$b =~ m|(\d*)/(\d*)/(\d*)|; return ( $a_yy<=>$b_yy || $a_mm<=>$b_mm || $a_dd<=>$b_dd); }
In reply to Re: Sorting rows in a text file
by thinker
in thread Sorting rows in a text file
by saihuj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |