We don't bite newbies here... much | |
PerlMonks |
Re: Read (sysread) binary data into utf8 stringby shmem (Chancellor) |
on Apr 03, 2017 at 23:38 UTC ( [id://1186924]=note: print w/replies, xml ) | Need Help?? |
Consider:
So this has nothing to do with IO layers; sysread apparently does substr, which just does the right thing. Magic. "\x{b5}" is an iso-8859-1 (a.k.a) latin1 char and a valid UTF8 codepoint, whose UTF-8 hex value is 0xC2B5 (0302 0265 as octal) - MICRO SIGN (µ).
Your file handle was set to raw, so bytes are read. Since perl places the byte into an UTF-8 string slot, it converts it from the internal representation into UTF8 and happily places its char hex value (2 bytes) into the PV slot, to satisfy the utf8-ness.
Similar to what happens here (reversed):
Except that the 'magic' bits are missing (since none involved).
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|