use Encode qw(decode);
sub decode_it {
my $s = shift;
eval {
$s = decode('UTF-8', $s, 1);
1;
} or do {
$s = decode('latin1', $s, 1);
};
return $s;
}
use Devel::Peek qw(Dump);
Dump decode_it($_) for "\xE2\x84\xA2", "\xE7\xE1";
__END__
SV = PV(0x100820708) at 0x10081c248
REFCNT = 1
FLAGS = (TEMP,POK,pPOK,UTF8)
PV = 0x100202140 "\342\204\242"\0 [UTF8 "\x{2122}"]
CUR = 3
LEN = 8
SV = PV(0x100820748) at 0x100860ee0
REFCNT = 1
FLAGS = (TEMP,POK,pPOK,UTF8)
PV = 0x10025dec0 "\303\247\303\241"\0 [UTF8 "\x{e7}\x{e1}"]
CUR = 4
LEN = 8
Once decoded by decode_it, your character strings are ready to be UTF-8 encoded right before you put it out onto your web page.
-
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.
|