Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: character substitution in search

by Ovid (Cardinal)
on Jun 19, 2000 at 20:13 UTC ( [id://18817]=note: print w/replies, xml ) Need Help??


in reply to character substitution in search

I am assuming that if your users are going to use your work, they probably have native keyboards (I've tried learning the French one and I can attest that they are a pain). This allows them to type in the alphabet of their choice.

If you wish to capture and use their input in that alphabet, you'll need to learn about using "locale". For example, the following fragment allows Perl to understand French characters.

#!/usr/bin/perl -w use locale; use POSIX 'locale_h'; my %locale = ( French => "fr_FR.ISO_8859-1", English => "us-ascii" ); setlocale(LC_TYPE, $locale{French}) or die "Invalid locale $locale{Fre +nch}\n";
You'll need to test this on your system as you may or may not have POSIX support.

The importance of this is being able to compare strings and have the sort order what you expect. Also, it can allow you to deal with upper- and lower-casing characters correctly and handle formatted prints as you expect.

For more information, see Perl locale handling. In the "See Also" section of this link, it lists POSIX(3) sixteen times, so I suspect you want to check that, also :)

As for allowing someone to match characters without accents (resumé|resume), you may wish to check out the String::Approx module from CPAN. Be forewarned, using String::Approx is slow. If performance is a consideration, you may wish to make this function optional for the end user.

Kudos to the Perl Cookbook on this one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-25 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found