perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:
How can my lower level routine know what format the stream is in (binary or unicode-text), so if the stream is in unicode, it can output unicode chars as '>8-bit values', OR if it is in 'binary', it can encode such values as UTF-8 so perl will see the stream as binary (and not complain about 'wide chars in output' -- and then do the conversion for me -- which seems to be it's current behavior).
I.e. If my lower level routine is about to print 'pi' in unicode, and the stream is a unicode stream, I'd print "\x{3c0}", but if it is a binary stream, I'd print "\xcf\x80" so the output would show 'π' in either case, w/o warnings.
I don't see a documented way of determining the current mode of a stream -- I need a "query-format" of the binmode directive so my 'blind' subroutine can _try_ to generate correct output in the face of unknown or random (user-based) input.
Thanks! ;-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to tell if a stream is already in UTF8 mode?
by VincentK (Beadle) on Jan 02, 2014 at 20:49 UTC | |
|
Re: How to tell if a stream is already in UTF8 mode?
by aitap (Curate) on Jan 02, 2014 at 21:53 UTC | |
by perl-diddler (Chaplain) on Jan 03, 2014 at 21:18 UTC | |
by ikegami (Patriarch) on Jan 05, 2014 at 18:46 UTC | |
|
Re: How to tell if a stream is already in UTF8 mode?
by ikegami (Patriarch) on Jan 05, 2014 at 18:43 UTC |