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.
| [reply] |
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)
| [reply] |