Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
$str =~ s/(^\x00-\x7F)/$table{'$1'} || '?'/ge; Are you planning to write a line like that for each of your accented letters? But then, what is the point of the %table hash? You might as well hard code everything (this is not what I am recommending). Depending on how your file is really encoded, the tr/// function might be much easier to use and probably faster. Something like this (to be completed): $str =~ tr/âàäçéèêë/aaaceeee/; There are a number of cases where this simple tr/// function works well. If not, well, then the Unicode modules described by others. There is a last point, though, which I can see as a problem, and which is in fact the main reason why I am posting here. "Unaccenting" letters may be less trivial than you may think. In French, all letters with an accent can be "unaccented" by just taking the same letter without the accent, this is the common way of doing things that when accents are not available. But in German, ä is usually rendered by ae, ö by oe and ü by ue. Similarly, I would tend to believe that the Scandinavian or other languages which have an 'å' probably don't translate it into an 'a'. This is just a warning that, depending on what exactly you are trying to do, your contemplated solution might be a bit simplistic. Update: crossed out the first paragraph following choroba's comment. I had misread the regex. In reply to Re: Unaccenting characters
by Laurent_R
|
|