From what I gather you want everything numerical only up front, followed by anything with a letter in it sorted asciibetically. Here is some code using the ever popular Schwartzian Transform:
use strict; use warnings; my %keys; @keys{('a'..'n')}= ('2','1','12','a12','a9', 'a2b3','a2b4','b2b4','1a2','a2bb5', 'a2bb5a','a2bb5b',654,9); my @foo = map { $_->[0] } sort newsort map { [$_, $keys{$_} =~ /^(\d+)$/ ? ($keys{$_},1) : $keys{$_} ] } keys %keys; print "KEY:$_ VALUE:$keys{$_}\n" foreach (@foo); sub newsort { if ( defined $a->[2] and defined $b->[2] ){ if ($a->[1] > $b->[1]) {return 1} return -1; } elsif ( defined $b->[2] or defined $a->[2]) { if ( defined $a->[2] ) { return -1 } return 1; } elsif ( $a->[1] gt $b->[1] ) { return 1; } elsif ( $b->[1] gt $a->[1] ) { return -1; } return 0; } #newsort __DATA__ KEY:b VALUE:1 KEY:a VALUE:2 KEY:n VALUE:9 KEY:c VALUE:12 KEY:m VALUE:654 KEY:i VALUE:1a2 KEY:d VALUE:a12 KEY:f VALUE:a2b3 KEY:g VALUE:a2b4 KEY:j VALUE:a2bb5 KEY:k VALUE:a2bb5a KEY:l VALUE:a2bb5b KEY:e VALUE:a9 KEY:h VALUE:b2b4
-enlil

In reply to Re: hash sort by value - Alpha Numeric by Enlil
in thread hash sort by value - Alpha Numeric by juo

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.