Hmm. I'm glad UV came up with h[er|is] solution, as mine was going to be similar, but involving the German double s that looks (sort of) like a Greek beta. Neither UV's solution nor mine showed the "feature" on Windows XP SP2 plus:-

This is perl, v5.8.4 built for MSWin32-x86-multi-thread
(with 3 registered patches, see perl -V for more detail)

Copyright 1987-2004, Larry Wall

Binary build 810 provided by ActiveState Corp. http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Jun  1 2004 11:52:21

The arrays came out the same, and in mine the order depended on whether 'use locale' was included.

Looking forward to the answer, GStC.


----- Original Message ----- From: "Ugly Virgin" <[EMAIL PROTECTED]>
To: "Jeff 'japhy' Pinyan" <[EMAIL PROTECTED]>
Cc: <beginners@perl.org>
Sent: Friday, August 12, 2005 11:53 AM
Subject: Re: Puzzle: Know Your Data


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>






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to