Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case independent sorting

How do I sort hash table by key (phonetically) I mean, if there is 3 keys in the hash table (called %tags), "MWE", "wPrefix", "conjunction", if I use the regular sort:

foreach $tag (sort keys %tags) {
    print "$tag\n";
}

The output I get is:

MWE
conjunction
wPrefix

But the output should be:

conjunction
MWE
wPrefix
like image 640
SharonKo Avatar asked Jun 24 '13 09:06

SharonKo


People also ask

What is case-sensitive sorting?

Sorting on the basis of the ASCII values differentiates the uppercase letters from the lowercase letters, and results in a case-sensitive order.

Is it possible to perform case-sensitive sorting?

Is it possible to perform (i) case sensitive sorting? (ii) columnwise sorting? Ans: (i) Yes Possible (ii) Yes Possible.

Is sorting case-sensitive in Excel?

Case Sensitive Sorting in Excel Thankfully, Excel allows you to specify whether you want the sorting to be case-sensitive or not.

What is case insensitive example?

Example of case-insensitivity:The email address may be entered as is or as [email protected], as it will be validated in both cases. In the case of passwords, a case-sensitive login process allows users to create more complex credentials by combining uppercase and lowercase letters, therefore reinforcing security.


1 Answers

Use the block code for sort function, comparing the upper case of each item:

foreach $tag (sort {uc($a) cmp uc($b)} keys %tags) {
    print "$tag\n";
}

This is a case-insensitive sorting, as @Dave Sherohman points

like image 109
Miguel Prz Avatar answered Sep 28 '22 07:09

Miguel Prz