http://www.perlmonks.org?node_id=492370


in reply to [ Natural Sort ]: Sorting a string with numbers

I love this site! I was writing my program, had a need for a routine that would do natural sorting, came right to the Monestary and Super Searched for "natural sort", and here I found this code, which worked almost perfectly!

Here is the one problem I have with it, and though I've read the write-up and follow-ups, and I think I get how it works, I can't seem to figure out a solution. The problem is this:

If the unsorted members of the list are something like ...
@list = ( 'apple1', 'apple', 'apple20' );

... then this routine will result in a sorted order of ...
apple1
apple20
apple

... but what I would expect (and want) would be ...
apple
apple1
apple20

I thought about going through my list beforehand, and appending something like "00000" to each member that didn't end in a numeric value, and then stripping the "00000" off after the sort, but that seems like a really stupid thing to do.

Can someone help me out please? Thanks!