http://qs321.pair.com?node_id=607749


in reply to locales, encodings, collations, charsets... how can I match a given MySQL collation?

Have a look at Unicode::Collate.
#!/usr/bin/perl use Unicode::Collate; my $coll = Unicode::Collate->new; my $e = "\xe9clair"; my @cmp = qw/ aardvark each eden zarkon /; for my $d ( @cmp ) { printf "%10s ccmp %5s = %d\n", $d, $e, $coll->cmp( $d, $e ); } __END__ aardvark ccmp éclair = -1 each ccmp éclair = -1 eden ccmp éclair = 1 zarkon ccmp éclair = 1
Update:: Another approach would be to use Text::Unidecode, and strip off any accents before doing the comparison.
  • Comment on Re: locales, encodings, collations, charsets... how can I match a given MySQL collation?
  • Download Code

Replies are listed 'Best First'.
Re^2: locales, encodings, collations, charsets... how can I match a given MySQL collation?
by xaprb (Scribe) on Apr 02, 2007 at 14:18 UTC

    I'm still nervous about this approach matching exactly MySQL. I need to match it exactly, even if MySQL's sorting is wrong, or the algorithm will run off the rails. I think varian's idea will probably work well. Thank you for the suggestions though!