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
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 (i) case sensitive sorting? (ii) columnwise sorting? Ans: (i) Yes Possible (ii) Yes Possible.
Case Sensitive Sorting in Excel Thankfully, Excel allows you to specify whether you want the sorting to be case-sensitive or not.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With