$! contains error message in locale's language and encoding as bytes, it isn't decoded into Unicode scalar:
$ LANG=ru_RU.UTF-8 perl -CS -MEncode=decode -E ' sub show { printf "is_utf8=%d, length=%d, msg=%s\n", utf8::is_utf8($_), length, $_; } $_=$!=111; show(); $_=decode("UTF-8", $_); show(); ' is_utf8=0, length=40, msg=Ð Ñоединении оÑказано is_utf8=1, length=21, msg=[here should be correct Russian "connection +refused" but perlmonks's parser turn it into html entities]
So, when we've nice Unicode-enabled application, which correctly write Unicode messages into UTF-8 log files, and then we get some error and try to write $! into log we get junk instead of error message.
It's clear what it's nearly impossible to manually decode('UTF-8') in each and every place we get $! - especially because this error may happens inside 3rd-party module. So, is it possible to somehow fix/workaround this issue without forcing LANG=en_US.UTF-8?
In reply to encoding for $! by powerman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |