in reply to Re: How to sort the data in Array which has format MMYY
in thread How to sort the data in Array which has format MMYY

Hi All,

When i try to sort the input data, i am not getting the wrong results

#!/usr/bin/env perl my (@months) = qw(Mar13 Jun13 Jul13 Apr13 ); my @mon = map uc, qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec +); my $mon; @{$mon}{@mon} = ( 0 .. $#mon ); sub by_month { my ($a_mon, $a_yy) = ($a =~ /(...)(..)/); my ($b_mon, $b_yy) = ($b =~ /(...)(..)/); $a_yy <=> $b_yy or $mon->{$a_mon} <=> $mon->{$b_mon}; } @months = ( sort by_month @months ); print "@months\n";

output

Mar13 Jun13 Jul13 Apr13

please help me on this</P<

Replies are listed 'Best First'.
Re^3: How to sort the data in Array which has format MMYY
by choroba (Cardinal) on Jul 03, 2013 at 15:29 UTC
    If your @months are no longer upper case, drop the uc.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ