good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: (Hopefully) simple sorting questionby AnomalousMonk (Archbishop) |
on Jun 03, 2011 at 11:33 UTC ( [id://907953]=note: print w/replies, xml ) | Need Help?? |
A real, sortable string together with its expected sorted output form would have been helpful, both to give the monks something to work with and to clarify the problem. (The apparently erroneous (x1,x1) first term also doesn't help.) ... sorted by the x co-ordinate, then by y. ... reorder the string by y co-ordinate first, then by x ... I'm confused by this as to whether you want to sort "by x then by y", or "by y then by x". I will assume the former. ... sorted by the x co-ordinate ... This suggests to me a Update: ascending numeric sort. Given these assumptions, here's an example of the sort of thing explained in Corion's link.
Note: The original string must be split into an array because sort only works on arrays. Update: Here's a version that will be significantly faster if you're sorting lotsa strings or very long strings. See A Fresh Look at Efficient Perl Sorting for a discussion.
In Section
Seekers of Perl Wisdom
|
|