in reply to best practices for a complex sort + splitting an alphanumeric string
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: best practices for a complex sort + splitting an alphanumeric string (natural)
by gabrielle (Novice) on Jan 13, 2006 at 20:42 UTC |