Jeff 'japhy' Pinyan wrote:
Here's an interesting exercise for beginners. You have an array of
strings, and you want to sort them but in a case-insensitive manner.
You are doing this in two different places in your code. In one place,
you write:
# convert the strings to lowercase when comparing
my @sorted = sort { lc($a) cmp lc($b) } @data;
And then later in your code, forgetting how you'd done it before, you use:
# convert the strings to uppercase when comparing
my @ordered = sort { uc($a) cmp uc($b) } @data;
But this gives you a headache: the arrays AREN'T IDENTICAL.
The puzzle to you is to determine the reason and sample data that
demonstrates the problem.
one possible answer: symbols in the data (specifically the ones between
the upper and lower case characters in ASCII)
$ perl -le'$,="\n";@a=("Hello", "_world!"); print sort {lc ($a) cmp lc
($b)[EMAIL PROTECTED]; print "\n", sort {uc($a) cmp uc ($b)[EMAIL PROTECTED]'
_world!
Hello
Hello
_world!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>