in reply to (tye)Re: Sorting by_number
in thread Sorting by_number
You can solve this by recasting it as an Shwartzian transform thus :-
This also gets rid of the offensive greps!my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { (my $a = $_) =~ s#(\d+)#"0".pack"N",$1#ge; [$_, $a] } @list;
This is likely to go wrong if embedded numerics are > 232 a problem which isn't easily solvable. In my original method these numbers should be automatically upconverted to doubles by perl avoiding the problem.
People who are puzzling out the above might like to consider replacing "0".pack"N",$1 with sprintf"%016d",$1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re2: Sorting by_number
by tye (Sage) on Sep 15, 2001 at 22:24 UTC |