Beefy Boxes and Bandwidth Generously Provided by pair Networks
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
in thread Unaccenting characters by mwhiting

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found