in reply to Re: Sort an array of strings based on two fields
in thread Sort an array of strings based on two fields

As a small variant, you can calculate a key by 100*year+month, assuming that month will always be two digit at most...
my @sorted = sort { ($a =~ /\.([0-9]+)-([0-9]+)\./, 100*$1+$2) <=> ($b =~ /\.([0-9]+)-([0-9]+)\./, 100*$1+$2) } @strings;
or would it be ok to insert the missing zero?
map { s/-(\d)\./-0\1./ } @strings; my @sorted = sort @strings;
(Make sure the regexp does not match elsewhere in your strings.)

Replies are listed 'Best First'.
Re^3: Sort an array of strings based on two fields
by choroba (Cardinal) on Mar 14, 2013 at 10:55 UTC
    I assumed 3 digits in the second solution. 50 seems too big for a months to me (maybe a week?)
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ