Advertisement
cd62131

sort by datetime

Dec 25th, 2018
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.65 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5. use open qw(:std :encoding(utf8));
  6. use DateTime::Format::Strptime q(strptime);
  7. my @plans = <DATA>;
  8. print for @plans;
  9. print "--\n";
  10. my @sorted = map { $$_[1] } sort { $$a[0] <=> $$b[0] } map {
  11.   /\d{4}-\d\d-\d\d \d\d:\d\d:\d\d/;
  12.   [strptime('%F %T', $&)->epoch, $_]
  13. } grep { /\d{4}-\d\d-\d\d \d\d:\d\d:\d\d/ } @plans;
  14. print for @sorted;
  15. __DATA__
  16. 場所=東京 時間=2018-12-25 10:00:00 持ち物=携帯電話
  17. 場所=千葉 時間=2018-12-18 16:00:00 持ち物=携帯電話
  18. 場所=埼玉 時間=2018-12-09 12:00:00 持ち物=携帯電話
  19. 場所=群馬 時間=2018-12-31 09:00:00 持ち物=携帯電話
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement