At the end of the day there has to be a lookup. That can be fairly quick using the translation function:
use warnings;
use strict;
my $str = <<'STR';
Les naïfs ægithales hâtifs pondant à Noël où il gèle sont sûrs d'être
+déçus et
de voir leurs drôles d'œufs abîmés
STR
my %xlateL = (
a => 'âà',
c => 'ç',
e => 'èëéê',
i => 'ïî',
o => 'ô',
u => 'ùû'
#...
);
my %xlateU;
$xlateU{uc $_} = uc ($xlateL{$_}) for keys %xlateL; #Generate the uppe
+r case versions
eval "\$str =~ tr/$xlateL{$_}/$_/;" for keys %xlateL;
eval "\$str =~ tr/$xlateU{$_}/$_/;" for keys %xlateU;
print $str;
Prints:
Les naifs ægithales hatifs pondant a Noel ou il gele sont surs d'etre
+decus et
de voir leurs droles d'œufs abimes
Note that æ causes a little grief however. Using a regex rather than the translation and a seperate set of tables is probably the fix for that.
This would make a good CPAN module when you've got it done. :)
DWIM is Perl's answer to Gödel
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|