How can I sort timestamps in Perl?

I have several thousand objects with a string property in a format "yyyy-MM-ddTHH:mm:ssZ". I want to sort these objects by time.

Are there any useful packages or scripts for this?

(Right now I'm just comparing individual numerical values ​​and it seems like this is not very efficient and neat.)

+3
source share
4 answers

You can use Time :: Local to convert the date to timestamp or one of Date :: modules from cpan. You can look this one to find out what is available.

, ( , , , , ).

, , . .

+3

sort . .

@sorted = sort @timestamps;
+7

, perl "sort" "cmp".

+5

, .

sub timeSort {

    my ($time) = ( shift =~ /\d{2}:\d{2}:\d{2}/ );
    return $time;
}

my @sortedList = sort { timeSort($a) <=> timeSort($b) } @oldList;
0

Source: https://habr.com/ru/post/1737919/


All Articles