Current Mood:  determined
Current Music: U2 - Love And Peace Or Else
If you tell Perl to sort an array of integers, which order does it sort them in? Hint: It's not numerical:> print join(', ', sort(1, 2, 10, 20, 100, 200));
1, 10, 100, 2, 20, 200ASCII order is already a lousy way to sort strings, but it's a completely nonsensical method for sorting integers.
Edit: Of course, you can sort in numerical order in Perl, using their (wacky) custom sort syntax:> print join(', ', sort{$a <=> $b}(1, 2, 10, 20, 100, 200));
1, 2, 10, 20, 100, 200But that syntax is really strange, and I'm still annoyed the default behavior isn't more sensible. (Incidentally, the case above also means that $a and $b are magic variables in this context, which means that overriding them can (apparently) cause bugs in some implementations of Perl. Argh...)
Note: <=> is the numerical comparison operator, as opposed to cmp, which is the (used-by-default) string comparison operator. |