in reply to encoding for $!

start your search here errno, errno -> Errno::AnyString - put arbitrary strings in $!

magic, magic -> Variable::Magic - Associate user-defined magic to variables from Perl.

You'll realize that these magic variables look a lot like tied variables. It is not surprising, as tied variables are implemented as a special kind of magic, just like any 'irregular' Perl variable : scalars like $!, $( or $^W, the %ENV and %SIG hashes, the @ISA array, vec() and substr() lvalues, threads::shared variables... They all share the same underlying C API, and this module gives you direct access to it.

t's nearly impossible to manually decode('UTF-8') in each and every place we get $! -

Should have used an abstraction :)  errno(), "@{[errno()]}",  @{[int errno()]}

Replies are listed 'Best First'.
Re^2: encoding for $!
by powerman (Friar) on Jun 29, 2014 at 01:18 UTC

    Thanks for the pointers, it was fun to play, but neither helps.

    With Errno::AnyString I'm able to change string value of $!, but looks like it doesn't matter how I set it - to Unicode scalar or binary UTF8-encoded string - because it always fetched as binary UTF8-encoded string.

    Variable::Magic doesn't actually see when $! set on errors, and even on manual set it sees (and can fake on get) only numeric value.

    I'm now on perl-5.16.3 so I didn't see this in doc before, but looks like perldoc perlvar for 5.20 mention this issue: «Note that when stringified, the text is always returned as if both "use locale" and "use bytes" are in effect. This is likely to change in v5.22.»