perl-unicode

Determining IO layer set on filehandle

2010-01-29 07:22:33
Filehandles may have IO layers applied to them, like :utf8 or :raw.
One of the ways to achieve that is to use the binmode() function.

  binmode $fh, ':utf8';

What I want to achieve is to set the STDOUT filehandle to ':raw' and
then to restore the previous IO layers.

  sub out_bin {
    binmode STDOUT, ':raw' or die "binmode: $!";
    print @_;
    # Restore previous IO layers here, but how?
  }

It is not satisfactory to do an explicit "binmode STDOUT ':whatever'"
after calling "print", because that would hardcode an assumption
about the caller's settings.

Is there a way to determine the IO layers applying to a filehandle
just from the filehandle itself?

Is there an alternative way to achieve what I want, maybe involving
one of the IO modules?

What's standard practice anyway?

-- 
Michael.Ludwig (#) XING.com

<Prev in Thread] Current Thread [Next in Thread>