Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Some code from Text::FIGlet might be of some use to you:
sub UTF8ord{ my $str = shift || $_; my $len = length ($str); return ord($str) if $len == 1; #This is a FIGlet specific error value return 128 if $len > 4 || $len == 0; my @n = unpack "C*", $str; $str = (($n[-2] & 0x3f) << 6) + ($n[-1] & 0x3f); $str += (($n[-3] & 0x1f) << 12) if $len ==3; $str += (($n[-3] & 0x3f) << 12) if $len ==4; $str += (($n[-4] & 0x0f) << 18) if $len == 4; return $str; } sub UTF8chr{ my $ord = shift || $_; my @n; #x00-x7f #1 byte if( $ord < 0x80 ){ @n = $ord; } #x80-x7ff #2 bytes elsif( $ord < 0x800 ){ @n = (0xc0|$ord>>6, 0x80|$ord&0x3f ); } #x800-xffff #3 bytes elsif( $ord < 0x10000 ){ @n = (0xe0|$ord>>12, 0x80|($ord>>6)&0x3f, 0x80|$ord&0x3f ); } #x10000-x10ffff #4 bytes elsif( $ord<0x20000 ){ @n = (0xf0|$ord>>18, 0x80|($ord>>12)&0x3f, 0x80|($ord>>6)&0x3f, 0x80|$ord&0x3f); } else{ warn "Out of range for UTF-8: $ord"; } return pack "C*", @n; }
I've tested it as far back as 5.00503 IIRC.

--
In Bob We Trust, All Others Bring Data.


In reply to Re: Encode fails to install on Win32 5.6 by belg4mit
in thread Encode fails to install on Win32 5.6 by roadrunner

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 chanting in the Monastery: (6)
As of 2023-02-08 01:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (40 votes). Check out past polls.

    Notices?