Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Default encoding rules leave me puzzled...

by tobyink (Canon)
on Jun 20, 2014 at 10:02 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found