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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |