setting binmode for empty filehandle

Discussion in 'Perl Misc' started by Helmut Richter, Apr 8, 2014.

  1. In an application, everything is Unicode. I though I would never have to
    worry if I set

    use utf8; # because the source is also UTF-8
    binmode (STDIN, ':utf8');
    binmode (STDOUT, ':utf8');
    binmode (STDERR, ':utf8');

    This would work for explicit usage of these filehandles and for implicit usage
    of STDOUT via "print" without a filehandle. It has, however, no effect on <>.

    Well between <> there is nothing, why not try

    binmode ('', ':utf8');

    but that does not help either.

    There is an obvious work-around: find myself the command line parameter with
    the file name and open it explicitly, or else use STDIN. Possible, but clumsy.

    Perhaps, the recommended way of dealing with *all files are Unicode* is
    something else. I am open to learn.
    Helmut Richter, Apr 8, 2014
    1. Advertisements

  2. Helmut Richter

    Peter Gordon Guest

    The below works fir me.

    use open ":encoding(UTF-16le)";
    binmode(STDOUT, "::encoding(UTF-16le)");
    while( <> ) {
    Peter Gordon, Apr 8, 2014
    1. Advertisements

  3. perl -CDS

    could be used achieve the desired effect.
    Rainer Weikusat, Apr 8, 2014
  4. use utf8; # because the source is also UTF-8
    this will give double encoding strings
    George Mpouras, Apr 8, 2014
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.