Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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


Comment on Re: Default encoding rules leave me puzzled...
Select or Download Code
Re^2: Default encoding rules leave me puzzled...
by kzwix (Acolyte) 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1090598]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2014-12-18 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (67 votes), past polls