⭐ in reply to How do I do a natural sort on an array?
See RE: RE: Re: Sorting on Section Numbers some important style comments.my @sorted= grep {s/(^|\D)0+(\d)/$1$2/g,1} sort grep {s/(\d+)/sprintf"%06.6d",$1/ge,1} @data;
Features and limitations:
- Strips extra leading zeros from digit strings
- Doesn't handle floating point numbers at all well
- Sorts negative integers in reverse after positive integers
- Uses very little extra memory
- You must specify the maximum number of digits your integers will have (6 in the above code)
|
---|
In Section
Seekers of Perl Wisdom