-
-
Save Util/5879369 to your computer and use it in GitHub Desktop.
A reply to the original (prefork) version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Data::Dumper; | |
my @files = ( | |
map( "/data/switch/cdr/SWITCH_20130627_151${_}00", qw( 8 5 9 7 6 ) ), | |
map( "/data/switch/otherCDR/SWITCH_20130627_151${_}00", qw( 9 6 8 5 7 ) ), | |
); | |
print Dumper \@files; | |
my @sorted = | |
map { unpack 'x[N] a*' } | |
sort | |
map { /SWITCH_\d{8}_(\d{6})/ or die; pack 'N a*', $1, $_ } | |
@files; | |
print Dumper \@sorted; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
my @files = | |
<8 5 9 7 6>.map({ "/data/switch/cdr/SWITCH_20130627_151{$_}00"}), | |
<9 6 8 5 7>.map({"/data/switch/otherCDR/SWITCH_20130627_151{$_}00"}); | |
say @files.perl; | |
my @sorted = @files.sort({ / SWITCH _ \d**8 _ (\d**6) / or die; $0; }); | |
say @sorted.perl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Spelling corrected: Schwartzian transform | |
2. No need to use parens around \d{8}. | |
3. I like ST better, but GRT is faster for large lists: | |
http://www.perlmonks.org/?node_id=145659 | |
4. Need to warn or die to show bad data when regex fails. | |
5. Perl 6 automatically does ST for you: | |
my @sorted = @files.sort({ / SWITCH _ \d**8 _ (\d**6) / or die; $0; }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./grt.pl # Same output as ST version | |
$VAR1 = [ | |
'/data/switch/cdr/SWITCH_20130627_151800', | |
'/data/switch/cdr/SWITCH_20130627_151500', | |
'/data/switch/cdr/SWITCH_20130627_151900', | |
'/data/switch/cdr/SWITCH_20130627_151700', | |
'/data/switch/cdr/SWITCH_20130627_151600', | |
'/data/switch/otherCDR/SWITCH_20130627_151900', | |
'/data/switch/otherCDR/SWITCH_20130627_151600', | |
'/data/switch/otherCDR/SWITCH_20130627_151800', | |
'/data/switch/otherCDR/SWITCH_20130627_151500', | |
'/data/switch/otherCDR/SWITCH_20130627_151700' | |
]; | |
$VAR1 = [ | |
'/data/switch/cdr/SWITCH_20130627_151500', | |
'/data/switch/otherCDR/SWITCH_20130627_151500', | |
'/data/switch/cdr/SWITCH_20130627_151600', | |
'/data/switch/otherCDR/SWITCH_20130627_151600', | |
'/data/switch/cdr/SWITCH_20130627_151700', | |
'/data/switch/otherCDR/SWITCH_20130627_151700', | |
'/data/switch/cdr/SWITCH_20130627_151800', | |
'/data/switch/otherCDR/SWITCH_20130627_151800', | |
'/data/switch/cdr/SWITCH_20130627_151900', | |
'/data/switch/otherCDR/SWITCH_20130627_151900' | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment