A few quick comments. This code:

if ($oids{ifName}{$a} =~ /\//) { @a = split(/\//, $oids{ifName}{$a}); @b = split(/\//, $oids{ifName}{$b}); } else { @a = $oids{ifName}{$a}; @b = $oids{ifName}{$b}; }

Can be replaced with simply:

@a = split m{/}, $oids{ifName}{$a}; @b = split m{/}, $oids{ifName}{$b};

And this code:

if ($a[0] =~ /[A-Za-z]/) { $a[0] ne $b[0] ? $a[0] cmp $b[0] : ($a[1] <=> $b[1] ? $a[1] <= +> +$b[1] : $a[2] <=> $b[2]); } else { $a[0] != $b[0] ? $a[0] <=> $b[0] : ($a[1] <=> $b[1] ? $a[1] <= +> +$b[1] : $a[2] <=> $b[2]); }

Can be replaced with:

if ($a[0] =~ /[A-Za-z]/) { $a[0] cmp $b[0] || $a[1] <=> $b[1]; } else { $a[0] <=> $b[0] || $a[1] <=> $b[1]; }

I'm sure there are other refinements, but these ones stood out to me immediately.

Update: perhaps the 2nd can even be simplified to:

$a[0] <=> $b[0] || $a[0] cmp $b[0] || $a[1] <=> $b[1];

I think so, but I haven't tested to make sure.

Another update: I noticed I left out the 3rd level comparison, but hopefully it should be obvious how to add it in. :-)


In reply to Re: best practices for a complex sort + splitting an alphanumeric string by revdiablo
in thread best practices for a complex sort + splitting an alphanumeric string by gabrielle

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.