in reply to SQLite (DBD) Sorting
You could sort using a routine to decompose the accented letter to their base characters. Something like this perhaps.
sub deaccent { my $phrase = shift; return $phrase unless ( $phrase =~ y/\xC0-\xFF// ); #short circuit + if no upper chars # translterate what we can (for speed) $phrase =~ tr/ÀÁÂÃÄÅàáâãäåÇçÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖØòóôõöøÑñÙÚÛÜùúûü +Ýÿý/AAAAAAaaaaaaCcEEEEeeeeIIIIiiiiOOOOOOooooooNnUUUUuuuuYyy/; # and substitute the rest my %trans = qw(Æ AE æ ae Þ TH þ th Ð TH ð th ß ss); $phrase =~ s/([ÆæÞþÐðß])/$trans{$1}/g; return $phrase; }
used as:
foreach my $row_db ( sort { deaccent($a) cmp deaccent($b) } @$selected + ) {
foreach my $row_db ( sort { deaccent($a->[1]) cmp deaccent($b->[1]) } +@$selected ) { my ($ID, $column1, $column2) = @$row_db; print "$column1\n"; }
Or as a Schwartzian Transform. (probably not worth it unless @$selected is large)
foreach my $row_db (map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { + [$_, deaccent($_)] } @$selected ) {
foreach my $row_db (map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { + [$_, deaccent($_->[1])] } @$selected ) { my ($ID, $column1, $column2) = @$row_db; print "$column1\n"; }
Note: this only covers ISO-Latin-1, if you need other code pages, modify deaccent() to suit (or possibly use Text::Unidecode)
UPDATE: fixed errors.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: SQLite (DBD) Sorting
by Anonymous Monk on Apr 29, 2010 at 18:19 UTC | |
by ikegami (Patriarch) on Apr 29, 2010 at 18:47 UTC | |
by thundergnat (Deacon) on Apr 29, 2010 at 18:48 UTC | |
by fanticla (Scribe) on Apr 30, 2010 at 09:02 UTC |