Yes, I've searched for that error message, but the solutions online haven't worked for me.

I have a text file that is a screen scrape by Automator on OS X. When I perform file: data.txt on Terminal, I get this: Big-endian UTF-16 Unicode English character data, with CR line terminators.

So I open it as UTF-16, but whenever I try to print something, I get the error in the title. I've boiled down my program to something so simple, it's trivial:

open (DATA, "<:encoding(utf16be)", "$filename") or die "Couldn't open +DATA: $!"; while (<DATA>) { print; } close DATA;

Why am I getting this error? The file doesn't appear to have any weird character when I open it with Text Editor. Could it be the carriage returns or something?

Update: I'm tried binmode STDOUT, ':utf8' and all I get is weird looking output. For example, here's my program and the data:

#!/usr/local/bin/perl use strict; use warnings; use diagnostics; open (DATA, "<:encoding(utf16be)", "data.txt") or die "Couldn't open +DATA: $!"; while (<DATA>) { binmode STDOUT, ':utf8'; print; } close DATA; __DATA__ Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus eu est quis nisi congue ornare. Suspendisse quis felis. Suspendisse placerat orci ut turpis. Suspendisse metus dolor, aliquet et, lobortis facilisis, fermentum ac, + massa. Cras nonummy lobortis urna. Aenean facilisis vulputate felis. Mauris pharetra malesuada quam.

The data is in a UTF-16 big-endian file with CR line terminators. Here's what I get when I run it:

Mauris pharetra malesuada quam.usernames-ibook-g4:~/desktop username$ ssa.

What the heck is going on? The text prints over itself; it's weird.


In reply to Wide character in print by kangaroobin

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.