note
Ovid
<p>Take a look at <a href="http://search.cpan.org/dist/Encode-DoubleEncodedUTF8/">Encode::DoubleEncodedUTF8</a>. The following returns your original string:</p>
<code>
#!/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;
</code>
<p><strong>Update:</strong> 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.</p>
<p>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.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-17000">
<p>Cheers,<br />
<a href="/index.pl?node=Ovid&lastnode_id=1072">Ovid</a></p>
<p><small><a href="http://www.allaroundtheworld.fr/">Hire me for training or software development</a>.</small></p>
</div></div>
1161728
1161728