KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have this quiz application where I match what people type with the right answer. For now, what I do is basically that : if ($input =~ /$answer/i) { print "you won"; } It's nice, as if the answer is "fish" the user can type "a fish" and be counted a good answer. The problem I'm facing is that, well, my users as I are french, and I'd like to be able to accept, say, a user typing "taton", and the answer being "tâton". So, what I could do, is : use POSIX qw(locale_h); use locale; setlocale(LC_TYPE, "fr_FR.ISO8859-15"); setlocale(LC_COLLATE, "fr_FR.ISO8859-15"); And in my check routine, do a : $input = lc($input); $input =~ tr/àáâãäåçèéêëìíîïñòóôõöùúûüýÿ/aaaaaaceeeeiiiinooooouuuuyy/; and something likewise with the answer. I don't like it, because I have to hard code things, and the day I decide I'm leaving the ISO-8859-15 world for the UTF-8 world, I'm doomed. So, I'm looking for a way to compare strings, that will make "tâton" eq "taton" , "maçon" eq "macon" or "macon" =~ /maçon/ be true.
Tags (comma-separated)
Save Edits
Cancel