That can certainly be done. All you have to do is to replace the last map block by something like:
map {
($date, $magnitude) = (split',')[3,4];
[$_, normalize($date), $magnitude]
}
Then you add a subroutine normalize which transforms your date-time string into a value (string or numerical) which has the same value for each "slot". For instance:
sub normalize {
my $value = shift;
my ($hours, $minutes, $seconds) = $value =~ m/(\d{2}):(\d{2}):(\d{
+2}\.\d{3})$/;
return int((1000 * $seconds + $minutes * 60 + $hours * 3600)/300);
}
As we now get a numeric result and not a string, we also have to replace the cmp in the sort block by a <=> to have the sort work correctly.With a little effort you can further parametrize the subroutine so you can define the "slot" in a more flexible way without having to rewrite the sub every time.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|