A fairly standard approach is to break the identifier up into a letter part and a number part, sort by each as needed, then join the bits back together again. There is a Perl idiom that makes that fairly easy and clean to do:

use strict; use warnings; my @rawList = qw( CORE1 COREA11 CORE12 COREA130 CORE8 CORE233 COREA12 COREA115 ); my @sortedList = # Join letter and number parts back together map{$_->[0] . $_->[1]} # sort first by letter part, then if that is equal sort by number +part sort {$a->[0] cmp $b->[0] || $a->[1] <=> $b->[1]} # Use a regex to split each item into a letter part and a number p +art map{[/([^\d]+)([\d]+)/]} @rawList; print join "\n", @sortedList;

Prints:

CORE1 CORE8 CORE12 CORE233 COREA11 COREA12 COREA115 COREA130

Note that map takes a list, processes each element, and returns a new list. The expression executes its main parts essentially from right to left: the last map executes first, then the sort, then finally the first map.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

In reply to Re: sorting number by GrandFather
in thread sorting number by dideod.yang

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.