Am 29.01.2010 um 15:37 schrieb Aristotle Pagaltzis:

> * Michael Ludwig <michael.lud...@xing.com> [2010-01-29 14:20]:
>> Is there an alternative way to achieve what I want, maybe
>> involving one of the IO modules?
> 
> You may want to just dup the filehandle and then diddle the dup’d
> one. You may need to `seek $origfh, (tell $dupfh), 0` afterwards.
> Not sure how much other state filehandles have that you might
> need to transfer, assuming that the state matters to you at all.

Thanks, Aristotle.

This is what I've come up with after some googling:

sub out_bin_good {
    open my $fh, '>&STDOUT' or die "dup STDOUT: $!";
    binmode $fh, ':raw' or die "binmode: $!";
    print $fh "BINÄR\t", @_;
}

Duplicating the filehandle does not affect the original STDOUT,
so no ugly surprises for the caller of this routine.

Anything else worth mentioning regarding this issue? Like, does
it work on all platforms?
-- 
Michael.Ludwig (#) XING.com

Reply via email to