Gossamer Forum
Home : General : Perl Programming :

Case insensative sort

Quote Reply
Case insensative sort
How can I make these sort routines case insensative?

@file = sort grep { /.tmp/} readdir(DIR);

foreach $record (sort keys %db_array) {
@db_array = split(/ /, $db_array{$record});
Quote Reply
Re: Case insensative sort In reply to
@files = sort { lc $a cmp lc $b } grep { /.tmp/ } readdir(DIR);

will do the first one, and for the second:

foreach $record (sort { lc $a cmp $b } keys %db_array) {

to sort case insensitive on the keys of the hash, or to sort on the values:

foreach $record (sort { lc $db_array{$a} cmp lc $db_array{$b}) {

The lc just makes the string lower case.

Hope that helps,

Alex
Quote Reply
Re: Case insensative sort In reply to
Alex, thanks!

Wayne