Wide character in setenv

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
http://perl.developpez.com/documentations/en/5.18.0/perl5180delta.html says
Wide character in setenv
Attempts to put wide characters into environment variables via %ENV now provoke this warning.

$ perl -we 'use diagnostics; use utf8;  $ENV="哇";'
Wide character in setenv at -e line 1 (#1)
    (S utf8) Perl met a wide character (>255) when it wasn't expecting
    one.  This warning is by default on for I/O (like print).  The easiest
    way to quiet this warning is simply to add the :utf8 layer to the
    output, e.g. binmode STDOUT, ':utf8'.  Another way to turn off the
    warning is to add no warnings 'utf8'; but that is often closer to
    cheating.  In general, you are supposed to explicitly mark the
    filehandle with an encoding, see open and "binmode" in perlfunc.

I need to use the use utf8 for other reasons.
Will any methods mentioned work?

Re: Wide character in setenv

Quoted text here. Click to load it

The same text also states that

    A value stored in an environment variable has always been
    stringified. In this release, it is converted to be only a byte
    string. First, it is forced to be only a string. Then if the
    string is utf8 and the equivalent of utf8::downgrade() works,
    that result is used; otherwise, the equivalent of utf8::encode()
    is used, and a warning is issued about wide characters

An obvious way to avoid the warning would therefore be to ut8::encode or
utf8::downgrade the string yourself. OTOH, just disabling the 'perl does
the right thing and we hate this' warning seems like a sensible
approach, too.

Re: Wide character in setenv

Quoted text here. Click to load it

Probably, diagnostics.pm will be updated accordingly.

Quoted text here. Click to load it
Quoted text here. Click to load it

No.  Layers are for IO::Handle and friends.  You should do it old-style:
explicitly decode after you read and explicitly encode before you write.
perluniintro.pod and friends have more.

Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

Site Timeline