Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi - I need some help figuring out something which should be fairly simple, in my mind.

I stole some code from a previous post (http://www.perlmonks.org/?node_id=609166) about how to unaccent characters in a string. I don't want to use the Text::Unaccent module, I want to just put in the simplified code suggested by salva in the above article. Here's the code I'm using, modified from his:

my %table = ( '' => 'A', '' => 'A', '' => 'A', '' => 'A', '' => ' +A', '' => 'A', '' => 'C', '' => 'E', '' => 'E', '' => 'E', '' => 'E', '' => 'I', '' => 'I', '' => 'I', '' => 'I', '' => 'N', '' => 'O', '' => 'O', '' => 'O', '' => 'O', '' => ' +O', '' => 'U', '' => 'U', '' => 'U', '' => 'U', '' => 'a', '' => 'a', '' => 'a', '' => 'a', '' => ' +a', '' => 'a', '' => 'c', '' => 'e', '' => 'e', '' => 'e', '' => 'e', '' => 'i', '' => 'i', '' => 'i', '' => 'i', '' => 'n', '' => 'o', '' => 'o', '' => 'o', '' => 'o', '' => ' +o', '' => 'ss', '' => 'u', '' => 'u', '' => 'u', '' => 'u', '' => 'y' ); $str = "Les Misrables"; $str =~ s/([^\x00-\x7F])/$table{'$1'} || '?'/ge; print "str:$str<br>";
Output is:
str:Les Mis?rables
I eliminated the subroutine and the 'shift' command that he had in his code. The code seems to notice that the character is in the right hex range, but it doesn't find the character to replace with.

A second problem: when I use this function on a string coming from the datafile content I will actually be using it on, it replaces it with two question marks, as in: Les Mis??rables. I have seen it convert the accented e to two characters with other methods I have been attempting to use too. Is this something about unicode conversions, using more than one byte to represent something?

Thanks! Michael


In reply to 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2014-12-20 23:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (99 votes), past polls