Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

As you know, the sort verb takes as one argument a subroutine (or an in-line block of code) whose job it is to return a value that is less than, equal to, or greater than zero when given two keys to compare.   It can be a separate subroutine, and I like to do it that way, especially when I have several occurrences of the same sort.

When dealing with date-values, I prefer to use a nice “date/time object” such as DateTime, which relieves me of all concerns about date/time handling.

But, when you can’t do that, you can do sorting of months by defining a hashref that gives you numeric equivalents for them.   So, your sorting subroutine becomes something like this:   (untested)

my %month_sort = ( 'JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6, ... etcetera ... ); sub sort_cmp { my ($a, $b) = @_; return ( substr($a, 3, 2) cmp substr($b, 3, 2) ) || ( $month_sort->{substr($a, 0, 3)} <=> $month_sort->{substr($b, 0, 3)} ); }

In reply to Re: How to sort the data in Array which has format MMYY by sundialsvc4
in thread How to sort the data in Array which has format MMYY by kum@12

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2018-03-17 19:26 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (225 votes). Check out past polls.