Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: The Queensrÿche Situation

by Jim (Curate)
on Oct 19, 2014 at 20:39 UTC ( [id://1104344]=note: print w/replies, xml ) Need Help??


in reply to The Queensrÿche Situation

If you only have to deal with Unicode—and you properly should only have to deal with Unicode in this millennium—then use the Unicode collation algorithm instead of something non-standard. In Perl, this means using Unicode::Collate. Both the Unicode collation algorithm and the Perl CPAN module Unicode::Collate are customizable.

use strict; use warnings; # This Perl script is Unicode UTF-8 use utf8; # Proper Unicode collation use Unicode::Collate; # The output of this Perl script is Unicode UTF-8 binmode STDOUT, ':encoding(UTF-8)'; my $fancy = 'Queensrÿche'; my $plain = 'Queensryche'; my $collator = Unicode::Collate->new( level => 1, normalization => undef, ); # This prints "Queensrÿche and Queensryche are the same word." printf "$fancy and $plain %s the same word.\n", $collator->eq($fancy, $plain) ? "are" : "aren't"; exit 0;

As it says in the script, this correctly prints "Queensrÿche and Queensryche are the same word." Whether or not this is exactly what's displayed in your terminal window is another matter altogether—one that's not related to the Perl script.

See Perl Unicode Cookbook: Case- and Accent-insensitive Comparison by Tom Christiansen (tchrist).

Update:  By the way, in this same configuration of Unicode::Collate, the strings "QUEENSRŸCHE" and "Queensryche" will compare equal as well.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1104344]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found