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

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

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (4)
    As of 2014-10-01 23:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      What is your favourite meta-syntactic variable name?














      Results (41 votes), past polls