[Moscow.pm] transform sort function to Schwartzian Transform ??
Denis Evdokimov
evdokimov.denis на gmail.com
Пт Сен 9 09:08:43 PDT 2011
А теперь ответ на вопрос
#!/usr/bin/perl
use strict;
use warnings;
use constant RegExp_parse_name =>
qr/([A-Z0-9]+_\d+_[A-Z0-9]+)_(\d+)-([A-Z][a-z]{2})-(20\d{2})_(\d+)[.]xml/;
my %months = (
FY => '00',
Jan => '01',
Feb => '02',
Mar => '03',
Apr => '04',
May => '05',
Jun => '06',
Jul => '07',
Aug => '08',
Sep => '09',
Oct => '10',
Nov => '11',
Dec => '12',
);
my @tmp_scons;
while ( my $str = <DATA> )
{
chomp($str);
my ( $trade_id, $date, $month, $year, $row_num ) = $str =~
RegExp_parse_name;
$trade_id or next;
$month = $months{$month};
push @tmp_scons, [ "$trade_id:$year-$month-$date:$row_num", $str];
}
my @scons = map $_->[1], sort {$a cmp $b} @tmp_scons;
foreach(@scons)
{
print "$_\n";
}
__DATA__
N1089767N_7_SWOPT_03-Jul-2011_78919186.xml
N1089767N_7_SWOPT_25-Jun-2011_72745892.xml
N1089772L_9_SWOPT_03-Jul-2011_78979055.xml
N1089772L_9_SWOPT_20-Jul-2011_69380887.xml
N1089772L_9_SWOPT_29-Jun-2011_74754662.xml
Подробная информация о списке рассылки Moscow-pm