in reply to Re: [ Natural Sort ]: Sorting a string with numbers
in thread [ Natural Sort ]: Sorting a string with numbers
gives:#!/your/perl/here use strict; use warnings; my @list = qw(apple1 apple apple20); my @sorted = @list[ map { unpack "N", substr($_,-4) } sort map { my $key = $list[$_]; $key =~ s[(\d+)][ pack "N", $1 ]ge; $key . pack "N", $_ } 0..$#list ]; print "@sorted\n";
Post your code and let's check it.apple apple1 apple20
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: [ Natural Sort ]: Sorting a string with numbers
by blueflashlight (Pilgrim) on Sep 18, 2005 at 02:01 UTC | |
by tye (Sage) on Sep 18, 2005 at 03:25 UTC | |
by blueflashlight (Pilgrim) on Sep 18, 2005 at 17:41 UTC |