in reply to How do I sort something alphabetically?
The default sort behavior with strings is "ASCIIbetical," rather than alphabetical. ASCII-wise, the capital letters (as a group) come before the lowercase (as a group); thus "D" comes before "a."
So assuming you want to sort a list of words, what you want is:
# make it a "sort sub" sub alphabetical { # compares lower-cased versions of the strings lc($a) cmp lc($b); } # to sort having defined this sub, you do @list = sort alphabetical @list;
Or, to avoid making a bunch of tiny little otherwise useless functions, sort also lets you use a block in place of a function:
@list = sort { lc($a) cmp lc($b) } @list
|
|---|