Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Take a look at Encode::DoubleEncodedUTF8. The following returns your original string:

#!/usr/bin/env perl use 5.18.0; use warnings; use utf8::all; use Encode; use Encode::DoubleEncodedUTF8; my $bytes = "\321\201\321\202\321\200\321\203\320\272\321\202\321\203\ +321\200\320\260"; my $fixed = decode( "utf-8-de", $bytes ); say $fixed;

Update: A strong word of caution about the above. Fixing "broken" Unicode data is fraught with error, particularly if you can't guarantee the source of the error. If this bad data is coming from outside your program, then try to contact whoever generates that bad data and see if you can get it fixed there. Otherwise, you may have to trust yourself to be lucky on this.

However, if the bad data is being generated from within your program, try to fix the underlying bug before you try to "fix" the bad strings in question. It will save you much grief in the long run.




  • 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 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 examining the Monastery: (2)
As of 2021-09-25 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?