Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Default encoding rules leave me puzzled...

by tobyink (Abbot)
on Jun 20, 2014 at 10:02 UTC ( #1090598=note: print w/replies, xml ) Need Help??

in reply to Default encoding rules leave me puzzled...

When you include the use utf8 pragma, all this says to Perl is that your script itself is written in UTF-8. It says nothing about what encoding it used by different filehandles.

Regardless of your environment, handles in Perl default to operating as binary byte streams. (The exact details depend on whether you're on an MS-DOS-like machine or a Unix-like machine, but the results are much the same.) This is documented in PerlIO.

Once upon a time (in Perl 5.8.0), Perl used to automatically pick up the locale from the environment. This was somewhat unpredictable and unexpected, and this feature was removed in the next Perl release (5.8.1).

Now, if you want Perl to sniff your environment you need to explicitly ask for it. With binmode or the open pragma, use the :locale layer.

You might also want to check out the -C command line option which provides some facilities for switching the standard input/output/error handles to UTF-8, either unconditionally or depending on your environment.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^2: Default encoding rules leave me puzzled...
by kzwix (Sexton) on Jun 20, 2014 at 12:55 UTC
    Thanks, I guess I had the misfortune of making my first steps with Encode under the 5.8.0 version, then. I'm glad there now is a "predictable" behavior instead.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090598]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2018-05-25 05:51 GMT
Find Nodes?
    Voting Booth?