Bonjour,
Im selecting values from a mysql column, for example....
Row1: abc
Row2: cde
Row3: efg
Row4: ABC
Row5: CDE
Row6: CDE
Row7: CDE
What I want to do is sort the values and remove duplicates. I've managed to write the code to select the values, sort and remove duplicates but the way I tried (recommended by perldoc) doesn't seem to want to let me sort without capitals coming first.
Code:
push @vals, $key[0];
}
undef %value;
@value{@vals} = ();
@sorted = sort keys %value;
Now that does the job nicely except I end up with:
ABC
CDE
abc
cde
efg
...does anyone know how I can sort case insensitively?
It isn't as easy as you think because the following doesn't work either:
@sorted = sort { lc($value{$a}) cmp lc($value{$b}) } keys %value;
Thanks!
Im selecting values from a mysql column, for example....
Row1: abc
Row2: cde
Row3: efg
Row4: ABC
Row5: CDE
Row6: CDE
Row7: CDE
What I want to do is sort the values and remove duplicates. I've managed to write the code to select the values, sort and remove duplicates but the way I tried (recommended by perldoc) doesn't seem to want to let me sort without capitals coming first.
Code:
Code:
while (my (@key) = $sth->fetchrow_array) { push @vals, $key[0];
}
undef %value;
@value{@vals} = ();
@sorted = sort keys %value;
Now that does the job nicely except I end up with:
ABC
CDE
abc
cde
efg
...does anyone know how I can sort case insensitively?
It isn't as easy as you think because the following doesn't work either:
@sorted = sort { lc($value{$a}) cmp lc($value{$b}) } keys %value;
Thanks!