> Ok, so now Lawrence would you be so kind as to give a little explanation as > to what is going on here? > > I can see that it works but to be honnest after the line: "my @sorted = " I > am lost... > > Thanks in advance, > > Rob Coops > >
Okay ... so, the basic algorithm is 1) turn a date into a twelve digit integer YYYYMMDDHHMM 2) simply sort those integers 3) turn it back into DDMMMYYYY.HHMM Remember that chains of maps are like transform matrices, they're executed from back to front... so in execution order @step1 = map { chomp; $_ } <DATA>; Just get the c/r terminated lines in the data block into an array @step2 = map { s|(\d{2})(\w{3})(\d{4})\.(\d{4})|$3${monthmap{$2}}$1$4| ; $_ } @step1 do a big search-and-replace, using $2 as a key into the hash %monthmap to turn "JAN" into 01 and "DEC" into 12. Keep in mind that s/// operates on $_ by default, but its return value is of limited interest. @step3 = sort @step2 That's the obvious part @step4 = map { s|(\d{4})(\d{2})(\d{2})(\d{4})|$3${reversemap{$2}}$1.$4|; $_ } @step3 Do the opposite of the first search-and-replace, using %reversemap, which has keys like '01' and '12' and values like 'JAN' and 'DEC'. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g Computer software consists of only two components: ones and zeros, in roughly equal proportions. All that is required is to sort them into the correct order. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>