in reply to Sort::Key::Natural sorting discrepancy
If you want alphanumeric groups to remain unbroken, you will have to change the sorting-key generation algorithm.
This probably does what you want (untested):
use Sort::Key qw(keysort); sub mknkey { my $n = shift; $n =~ s/^0+//; my $len = length $n; my $nines = int ($len / 9); my $rest = $len - 9 * $nines; ('9' x $nines) . $rest . $n; } sub mknatkey { my $nat = @_ ? shift : $_; $nat =~ s/(\d+)/mknkey($1)/ge; $nat; } my @sorted = keysort { mknatkey($_) } @data;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort::Key::Natural sorting discrepancy
by 1nickt (Canon) on Nov 01, 2017 at 14:01 UTC | |
by salva (Canon) on Nov 01, 2017 at 16:44 UTC | |
|
Re^2: Sort::Key::Natural sorting discrepancy
by cr8josh (Sexton) on Nov 01, 2017 at 15:56 UTC |