<?xml version="1.0" encoding="windows-1252"?>
<node id="875357" title="Encoding SQLite Accents Ordering" created="2010-12-04 06:11:57" updated="2010-12-04 06:11:57">
<type id="115">
perlquestion</type>
<author id="872655">
welle</author>
<data>
<field name="doctext">
&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;I'm searching for your wisdom concerning an encoding issue. I'm reading a SQLite database with data encoded in utf-8. I need to the data order alphabetically and print them out. Here is the problem with accented characters. I am using the following code (it worked perfectly with an older SQLite DB without UTF8 data.&lt;/p&gt;
&lt;code&gt;
sub alpha_order{
$dbh = DBI-&gt;connect( "dbi:SQLite:files/database/data.db" ) || die "Cannot connect: $DBI::errstr";

foreach my $row_db ( sort { deaccent($a-&gt;[2]) cmp deaccent($b-&gt;[2]) or $a-&gt;[2] cmp $b-&gt;[2] } @$all_db_orderd ) {
    my ($ID, $col1, $col2) = @$row_db;
    
    #encoding in utf8 for printing
    $col1= Encode::decode_utf8( $col1 );
    $col2= Encode::decode_utf8( $col2 );

#Printing data out
}
}

sub deaccent {
    my $in = $_[0];
    return lc($in) unless ( $in =~ y/\xC0-\xFF// ); #short circuit if no upper chars
    # translterate
    $in =~ tr/ÀÁÂÃÄÅàáâãäåÇçÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖØòóôõöøÑñÙÚÛÜùúûüÝÿý/AAAAAAaaaaaaCcEEEEeeeeIIIIiiiiOOOOOOooooooNnUUUUuuuuYyy/;
    $in =~ tr/'//d; 
    return lc($in);
}
&lt;/code&gt;
&lt;p&gt;As I said before, it worked well order-&gt;aäbcoö with my old SQLite DB (no UTF data). Now unfortunatly I populate the DB with UTF-data and when I read out the data from the DB ordering it with the above script, I can't order the data properly. I get something as order-&gt;abcoäö&lt;/p&gt;
&lt;p&gt;Any idea what I am doing wrong? Encoding issues in Perl drive me crasy.... Welle&lt;/p&gt;</field>
</data>
</node>
