Saying that the input "contains unicode" is not enough to understand the problem. Unicode can be conveyed in at least three different ways: UTF-16BE, UTF-16LE and UTF-8. The first two differ only in the byte-order of 16-bit "words" (in the computer science sense of "groupings of two bytes"), and both are substantially different from the third option.

When you say "lines with unicoding don't get output to a file", do you mean that some lines really are composed entirely of plain ASCII characters (and these get through just fine)? If so, then the data probably is UTF-8, because this encoding was designed so that ASCII characters, which are a small subset of Unicode, can be conveyed in their original single-byte form.

If you have Perl 5.8.x (hopefully, "x" is greater than 0), then it might be enough for you to check out the usage of the "-C" option when running perl (look it up with "perldoc perlrun") -- "-CS" means treat STDIN, STDOUT and STDERR as utf8-protocol file handles; "-CD" means treat any named files that are opened for input and output as having utf8-protocol.

You can also selectively apply utf8-protocol to specific file handles using "binmode( HANDLE, ":utf8" );" (in case you need the same script to also handle files that contain non-text binary data). Look that up with "perldoc perlunicode" in 5.8.x.

If your data are some other form of unicode, you'll probably want to use 5.8.x and the "Encode" module, to convert from the (external) UTF-16 form to (perl-internal) utf8 -- and back to UTF-16 if you want to keep that as your storage format.

If none of this helps, you'll need to post some code and sample data that demonstrate the problem you're having.


In reply to Re: Unicode in Perl by graff
in thread Unicode in Perl by lorylover

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.