I'm looking for a logical (not additional module) to sort by such format. I have a list of strings which looks like:
asdadasBBBsfasdasdas-0112
asdanfnfnfnfnf222ads-1210
etc. I cant just sort by the numbers, because, for instance: 812 > 113 (812 = August 2012, 113 = January 2013, so its incorrect)
any good strategy??
thanks,
On the Data tab, in the Sort & Filter group, click Sort. In the Sort dialog box, do the following: Under Column, select the name of the column that contains the month names. Under Sort on, choose Cell Values.
Drag down the column to select the dates you want to sort. Click Home tab > arrow under Sort & Filter, and then click Sort Oldest to Newest, or Sort Newest to Oldest.
Insert a blank column next to your Date column. Assuming your first date is in cell A4, in the blank column, enter the formula: =TEXT(A4,"MMDD") Copy this formula down to the bottom of your data. Sort your data on this column.
Go to the database tab, select month name column from your calendar table. Select the modeling tab and then "Sort by Column" and select your month number column. Month name should now appear in the correct order.
A schwartzian transform would be a huge waste here. This similar construct whose name I can never remember would be way better.
my @sorted =
map substr($_, 4),
sort
map substr($_, -2) . substr($_, -4, 2) . $_,
@unsorted;
Using the match operator instead of substr
:
my @sorted =
map substr($_, 4),
sort
map { /(..)(..)\z/s; $2.$1.$_ }
@unsorted;
How about Schwartzian transform:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dump qw(dump);
my @list = (
'asdadasBBBsfasdasdas-0112',
'asdanfnfnfnfnf222ads-1210',
'asdanfnfnfnfnf222ads-1211',
'asdanfnfnfnfnf222ads-1010',
'asdanfnfnfnfnf222ads-1011',
);
my @sorted =
map { $_->[0] }
sort { $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] }
map { /-(\d\d)(\d\d)$/; [$_, $2, $1] } @list;
dump @sorted;
output:
(
"asdanfnfnfnfnf222ads-1010",
"asdanfnfnfnfnf222ads-1210",
"asdanfnfnfnfnf222ads-1011",
"asdanfnfnfnfnf222ads-1211",
"asdadasBBBsfasdasdas-0112",
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With