Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: encoding for $!

by powerman (Friar)
on Jun 28, 2014 at 21:54 UTC ( [id://1091571]=note: print w/replies, xml ) Need Help??


in reply to Re: encoding for $!
in thread encoding for $!

I can and I do. But this routine log not only $! but any messages, and thus expect _correct_ scalars - i.e. if it contain non-ASCII chars then it must be Unicode string (utf8::is_utf8 should return true).

At every point where app receive text from outside world (stdin,@ARGV,CGI params,network,database) it decode from bytes to Unicode using known encoding. At every point where app output text to outside world (stdout,files,logs,network,etc.) it encode Unicode into bytes using known encoding. Between input and output all text in scalars is in Unicode. Now, we get $! somewhere in the middle of the app, and turns out this is one more "receive from outside world" point where we should decode bytes to Unicode - but doing this everewhere we may get $! is too unconvenient.

Replies are listed 'Best First'.
Re^3: encoding for $!
by RonW (Parson) on Jul 01, 2014 at 16:10 UTC

    As was pointed out by an anonymous monk on Jun 29, 2014, Perl has an UFT-8 flag you can test(see perlunicode and related).

    Since you know the locale your program is running with, for any message your central logging routine receives that is not flagged as UFT-8, you could then convert it.

    (not tested, so not sure if this would work)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found