分页: 1 / 1

Perl - 日期时间排序

发表于 : 2017年02月17日 17:44
523066680
原问题 http://bbs.bathome.net/thread-43203-1-1.html

Code: [全选] [展开/收缩] [Download] (Untitled.bsh)
  1. use Encode;
  2. use IO::Handle;
  3. STDOUT->autoflush(1);
  4.  
  5. open READ, "<:encoding(gbk)", "src.txt";
  6. my %hash;
  7. for my $e ( <READ> )
  8. {
  9.     $e=~s/\r?\n$//;
  10.     if ($e=~/(\d+)\p{han}(\d+)\p{han}(\d+)\p{han}(\d+)\p{han}(\d+)\p{han}(\d+)\p{han}/)
  11.     {
  12.         $t = sprintf("%d%02d%02d%02d%02d%02d", $1, $2, $3, $4, $5, $6 );
  13.         $hash{ $t } = $e;
  14.     }
  15. }
  16. close READ;
  17.  
  18. grep { print encode('gbk', $hash{$_}),"\n" } ( sort keys %hash );