Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I am running a script on Mac OS X that uses DBI to connect to FrontBase. The DBD:FB module seems to be returning everything in Unicode. Things mostly work except for when I am dealing with diacritics being passed to unicode unaware programs, at which point é is morphed into √©, ä is turned into √§ and so on. I made a sub that did this:
sub sanitize { my $string = shift; $string =~ s/[àáâãäå]/a/; $string =~ s/[ÀÁÂÃÄÅ]/A/; $string =~ s/ç/c/i; $string =~ s/[èéêë]/e/; $string =~ s/[ÈÉÊË]/E/; $string =~ s/[ìíîï]/i/; $string =~ s/[ÌÍÎÏ]/I/; $string =~ s/ñ/n/; $string =~ s/Ñ/N/; $string =~ s/[òóôõöø]/o/; $string =~ s/[ùúûü]/u/; $string =~ s/[ÙÚÛÜ]/U/; return($string); }
but it does not work. None of the characters are converted, though if I use the sub on non-unicode text it works fine. I am sure the sub could be simplified, but right now I am just trying to get it to work at all.
I tried 'use UTF-8' thinking it might be needed, but then it gives this error "Malformed UTF-8 character at line xx" for each line of the regex, and again it does work on non-unicode, but does not work on unicode encoded text.

For now I know where the particular pieces of data that are problems are and I just match them with .*, and fix things, but I really want to have a more generic way of fixing this. I didn't see anything in the perlunicode perldoc that seemed to help other than "WARNING: The implementation of Unicode support in Perl is incomplete," which makes me think maybe it either imperfect Unicode support or Mac OS X flakiness, and not just me missing something. But the docs do say

"The existing regular expression compiler does not pro- duce polymorphic opcodes. This means that the deter- mination on whether to match Unicode characters is made when the pattern is compiled, based on whether the pattern contains Unicode characters, and not when the matching happens at run time."

I do not know how to interpret that and I would be very interested to hear what it means in terms of what I am trying to do. Also I wanted to ask the many knowledgeable folks here if anyone knew of a way to strip out diacritics in unicode, strip them in general (since my sub seems like it must be a re-invention but I could not find anything like it) or if perhaps I was missing something somewhere else that was relevant to my problem of flattening out diacritics.

In reply to questions about character encoding by moof1138

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? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2023-06-06 02:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (26 votes). Check out past polls.

    Notices?