"be consistent" | |
PerlMonks |
Re: sorting an array of file namesby bobf (Monsignor) |
on Dec 19, 2009 at 16:41 UTC ( [id://813534]=note: print w/replies, xml ) | Need Help?? |
The default sort order is lexical. If you want a numeric sort, you need to specify a sort routine using the <=> operator (see perlop). See sort for more information. Since your filenames have both numeric and alpha components, you will probably need to split the pieces apart before doing the comparison. The Schwartzian Transform is good for this kind of thing. Here is one approach. Extend the sort routine as needed if you want to specify a secondary/etc sort order in the event two filenames start with the same numeric component.
Love those pdb files. :-) Lipase, huh? Interesting stuff.
In Section
Seekers of Perl Wisdom
|
|