[Pdx-pm] Some filehandle help needed
Michael G Schwern
schwern at pobox.com
Tue Aug 7 14:52:01 PDT 2007
Kyle Dawkins wrote:
> This works (feel free to tell me a better way to deal with the fh,
> too... I need to use getc, so using IO::Handle seemed the best way to
> do it... maybe that's my prob?):
>
> ...
> my $_tty = _tty();
> open my $_fout, "> /dev/$_tty";
> my $fout = IO::Handle->new_from_fd($_fout, "w");
Though its not clear from the docs, new_from_fd() takes a file *descriptor*
not a file handle. Yes, its a ridiculous interface for a Perl module.
My guess as to why it works inline but not in a subroutine is that $fout does
not actually store a reference to $_fout but just its fileno. Once $_fout
goes out of scope the filehandle closes. That's my guess.
IO::Handle was written in the days before lexical filehandles and doesn't seem
to have caught up.
More information about the Pdx-pm-list
mailing list