in reply to manipulating array
This seems over-long, but unless you write a more complex sort comparator (and hide the date parsing and processing etc in there) I'm not sure it can get much shorter. I don't like debugging complex sort comparators, so there you go.# Each eat of splitLines will hold an array ref my @splitLines; foreach my $line (@calls) { my @bits = split(/\s+/, $line, 4); # Discard the first column shift @bits; # We want to sort by date, so we'll parse # the date column and prefix with a sortable value my ($mday, $month, $year) = split(m!/!, $bits[1]); $month -= 1; # mktime wants month from 0 $year += 100; # mktime wants year from 1900 my $when = POSIX::mktime(0, 0, 0, $mday, $month, $year); unshift @bits, $when; push @splitLines, [ @bits ]; } # Sort by first elt @splitLines = sort { $a->[0] <=> $b->[0] } @splitLines; # And puts the lines back together again (discarding # the leading 'when'. @calls = map { shift @$_; join(' ', @$_) } @splitLines;
|
|---|