|
|
| Just another Perl shrine | |
| PerlMonks |
Re: sorting stringby davido (Bishop) |
| on Aug 28, 2005 at 07:11 UTC ( #487227=note: print w/ replies, xml ) | Need Help?? |
|
Try this:
Note, this illustrates the contortions you put yourself through by using variables such as $string1, $string2, and $string3 when you really ought to be using a proper array such as @strings. Look at how the snippet improves if you use a proper array:
It could also be written as:
Or even...
By the way; the title to your question, "Sorting strings" seems to be a misnomer, since in your question you seem to be asking how to sort numeric values. Maybe I've missed the point. But if you're trying to sort ascii-betically (instead of numerically), use the cmp operator instead of <=>. This and more is discussed in sort. Dave
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||