#!perl use strict; use warnings; #define my @result; my $line; my $key; my %months; my %sort_dates; my @sortedresult; #read in the data respective with dates etc. @result = ("AUDIO2-A3.12_P1:project:BmwWtz#1 Wed May 31 13:35:31 2006\n", "AUDIO2-A3.00_P1:project:BmwWtz#1 Wed Sep 34 11:22:57 2006\n", "AUDIO2-A3.30_P1:project:BmwWtz#1 Wed Sep 13 00:00:00 1999\n", "AUDIO2-A2.17_P1:project:BmwWtz#1 Wed Sep 20 30:06:45 1870\n", "AUDIO2-A5.17_P1:project:BmwWtz#1 Wed Sep 13 17:45:63 2220\n", "AUDIO2-A9.8:project:BmwWtz#1 Mon May 30 18:18:02 2006\n"); #declare array converting letter months to number months %months = ( "Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12" ); #define sort_dates array %sort_dates = (); @sortedresult = (printsorted(@result)); sub printsorted { my $string_line; my @result = @_; #declare local parameter #take the data from months and input it with the rest of the string foreach $string_line (@_) { $string_line =~ tr/ //s; #removes spaces ... wasnt working before but works now if( $string_line =~ /(.*#[0-9])\s+[a-zA-Z]{3} ([a-zA-Z]{3}) (\d{1,2}) (\d{2}):(\d{2}):(\d{2}) (\d{4})$/ ) { #sorts out sparts via regex $sort_dates{$7.$months{$2}.$3.$4.$5.$6} = $1; } } #use sort keys to sort array then arrange key with the sorted dates for $key(sort keys %sort_dates){ print $key,"-rel->",$sort_dates{$key},"\n"; } return(@sortedresult); }