I was needing something cheap that would work on both 5.6.x and 5.8.x versions. (I'm trying to keep the code the same while moving back and forth between systems) Tried your utf8_to_latin1() and ran into problems on 5.8.x. The below seems to work on both versions. Thanks for the code.
sub utf8_to_latin1 {
# return( pack("U0C*", unpack( "U*",@_[0]) ) );
return( pack( "C*", unpack("U0U*",@_[0]) ) );
}
Updated: (see sig) So I go and feed the original (commented out) line into the big program and it fails. It worked in the test program on both 5.6 and 5.8. Wander all over and find the 5.8 perluniintro where they explicitly say
$native_string = pack("C*", unpack("U*", $Unicode_string));
just like the original poster. But that didn't work alike on both Perl versions. Played around some more and hit upon the other variant above. This now works in both test and 'real' programs on both Perl versions. (sigh)
--
I'm a pessimist about probabilities; I'm an optimist about possibilities. - -
Lewis Mumford
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.