When you work with Unicode, you should get greater character codes (>=255), not byte sequences, because Perl encapsulates encodings for you. For example,
use utf8;
binmode STDOUT, ":utf8";
my $string = "Queensrÿche ы";
printf "%x\t%s\n", ord($_), $_ for split "", $string;
__END__
51 Q
75 u
65 e
65 e
6e n
73 s
72 r
ff ÿ
63 c
68 h
65 e
20
44b ы
If you need to work with utf-8 bytes, encode them back:
use utf8;
use Encode 'encode';
binmode STDOUT, ":utf8";
my $string = "Queensrÿche ы";
printf "%x\t%s\n", ord($_), $_ for split "", encode utf8 => $string;
__END__
51 Q
75 u
65 e
65 e
6e n
73 s
72 r
c3 Ã
bf ¿
63 c
68 h
65 e
20
d1 Ñ
8b
But there would be no point in using utf8 and Encode in this case.
-
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.
|