Sorting case insensitively

J

John Deuf

Is there a way to sort case insensitively an array (without creating
another array with lowercase values for instance) ?
 
A

Andreas Kahari

Is there a way to sort case insensitively an array (without creating
another array with lowercase values for instance) ?


sort { uc($a) cmp uc($b) } @arr;
 
U

Uri Guttman

AK> sort { uc($a) cmp uc($b) } @arr;
BE> my @sorted = sort { lc $a cmp lc $b } @unsorted;

now make up your minds!! which one of those is better? will there be
another war on uc vs lc?

:)

uri
 
B

Ben Morrow

Uri Guttman said:
AK> sort { uc($a) cmp uc($b) } @arr;

BE> my @sorted = sort { lc $a cmp lc $b } @unsorted;

now make up your minds!! which one of those is better? will there be
another war on uc vs lc?

I thought there was a Right Answer to this: lc, as Unicode defines
mappings upper -> lower and title -> lower...?

Ben
 
M

Master Web Surfer

[This followup was posted to comp.lang.perl.misc]

Is there a way to sort case insensitively an array (without creating
another array with lowercase values for instance) ?


@sorted = sort { uc($a) cmp uc($b) } @data;

# Note that you could also use "lc" instead of "uc" in
# the sorting specification
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top