Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Into this:$arr = [ '1 - foo - xxx', '5 - foo - abc', '4 - foo - efg', '2 - foo - atc', '3 - foo - ggg', '1 - bar - aaa', '2 - bar - ttt', '3 - bar - xxx', '5 - bar - akk', '4 - bar - jjg', '1 - bar - atc', '2 - bar - yyg', '5 - bar - gga', '3 - bar - ttt', '4 - bar - gag' ];
So $arr is sorted on the basis of it's numerical value series (1,2,3,4,..N). In this case N=5, and N can be anything.$sortedar = [ '1 - foo - xxx', '2 - foo - atc', '3 - foo - ggg', '4 - foo - efg', '5 - foo - abc', '1 - bar - aaa', '2 - bar - ttt', '3 - bar - xxx', '4 - bar - jjg', '5 - bar - akk', '1 - bar - atc', '2 - bar - yyg', '3 - bar - ttt', '4 - bar - gag' '5 - bar - gga', ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to Sort Numerical String
by Joost (Canon) on May 17, 2007 at 11:55 UTC | |
|
Re: How to Sort Numerical String
by derby (Abbot) on May 17, 2007 at 12:24 UTC | |
|
Re: How to Sort Numerical String
by scorpio17 (Canon) on May 17, 2007 at 13:23 UTC |