FYI, since we're running benckmarks:
#!/usr/bin/perl use warnings; use strict; use Benchmark 'cmpthese'; use Sort::Naturally 'nsort'; use Sort::Key::Natural 'natsort'; my @data = grep /\S/, <DATA>; sub normalize_digits { my ( $key ) = @_; $key =~ s/(\d+)/sprintf '%03d', $1/eg; return $key; } cmpthese -10, { SN_nsort => sub { my @s = nsort @data }, SKN_natsort => sub { my @s = natsort @data }, GRT_pack => sub { my @s = map unpack( 'x3 a*', $_ ), sort map pack( 'n a a*', /(\d+)([A-Z])/, $_ ), @data }, ST_sub => sub { my @s = map { $_->[ 0 ] } sort { $a->[ 1 ] cmp $b->[ 1 ] } map { [ $_, normalize_digits( $_ ) ] } @data }, GRT_sub => sub { my @s = map { local $_ = $_; s/^.*\0//; $_ } sort map { normalize_digits( $_ ) . "\0$_" } @data }, GRT_sprintf => sub { my @s = map { s/-0+/-/g; $_ } sort map { s/(\d+)/sprintf '%03d', $1/eg; $_ } @data }, }; __DATA__ K-2-D-10A K-2-D-10C K-2-D-10D K-2-D-10E K-2-D-10F K-2-D-10G K-2-D-11A etc. etc.

Which gave me these results:

Rate SN_nsort SKN_natsort ST_sub GRT_sub GRT_sprint +f GRT_pack SN_nsort 64.6/s -- -81% -90% -91% -93 +% -97% SKN_natsort 341/s 427% -- -47% -51% -62 +% -82% ST_sub 642/s 893% 88% -- -7% -29 +% -67% GRT_sub 694/s 973% 104% 8% -- -23 +% -64% GRT_sprintf 900/s 1292% 164% 40% 30% - +- -53% GRT_pack 1928/s 2883% 466% 200% 178% 114 +% --

:-)


In reply to Re^3: Sorting question by jwkrahn
in thread Sorting question by perl_seeker

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!
  • 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, details, 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, summary, 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.