in reply to How to tell if a stream is already in UTF8 mode?
To me, this looks like an XY Problem. It doesn't sound like a good thing to make a "lower level routine" distinguish between different kinds of file handles with different IOLayers tied upon them. Where does your routine get filehandles from? Why they are opened in different modes? Wouldn't it be a better idea to binmode it some appropriate IOLayer like :utf8 or :encoding(...) on an upper level of subroutines?
Anyway, you can use PerlIO::get_layers($fh) to get the list of layer names on a filehandle (got from PerlIO perldoc page). Checking whether filehandle is in utf-8 mode is then reduced to grepping for the "utf8" string (usually the last element of the array).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to tell if a stream is already in UTF8 mode?
by perl-diddler (Chaplain) on Jan 03, 2014 at 21:18 UTC | |
by ikegami (Patriarch) on Jan 05, 2014 at 18:46 UTC |