Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

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

There are lots of ways to get about a 50% speed increase over an ST. Creating all of those tiny anonymous arrays isn't a speedy task. It does lead to rather simple and non-error-prone code, however.

One alternative that is as general purpose is to build a separate array of keys to sort on and then sort a list of indices from that:

my @sorted= do { my @sorton= map { get_date($_) } @data; my @indices= sort { $sorton[$a] cmp $sorton[$b] } 0..@data; @data[@indices]; };
Another alternative that can be slightly faster but is a bit harder to customize is to combine the key to sort on with the original data into a single string in a reversible manner and use:
my @sorted= map { restore_orig_data($_) } sort map { prepend_sort_key($_) } @data;
See also http://www.sysarch.com/perl/sort_paper.html or even http://www.perl.com/doc/FMTEYEWTK/sort.html.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: The Ovidian Transform by tye
in thread The Ovidian Transform by Ovid

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
  • 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?
    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: (15)
    As of 2015-07-28 20:17 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (258 votes), past polls