I'd use something similar to one of the techniques found by searching for natural sort. Likely:
my @sortedIdx= map { unpack "N", substr($_,-4) } sort map { my $key = $oids{ifName}{$_}; $key =~ s[(\d+)][ '0' . pack "N", $1 ]ge; $key . pack "CN", 0, $_ } keys %{$oids{ifName}};
Though I'm a little curious why your integer indices are used to index a hash not an array. If your keys aren't just integers, then you'll need:
my @keys= ( keys %{$oids{ifName}} )[ map { unpack "N", substr($_,-4) } sort map { my $key = $oids{ifName}{$_}; $key =~ s[(\d+)][ '0' . pack "N", $1 ]ge; $key . pack "CN", 0, $_-1 } 1 .. keys %{$oids{ifName}} ];
(Updated)
- tye
In reply to Re: best practices for a complex sort + splitting an alphanumeric string (natural)
by tye
in thread best practices for a complex sort + splitting an alphanumeric string
by gabrielle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |