Do you know where your variables are? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
First, I gotta take issue with your unnessesary and obfusicating use of subroutines. If a subroutine takes no arguments and returns nothing, don't use it. Really, you are just creating a block that has a name. All the real work is done implicitly. Almost always implicit modification of globals is a VERY BAD IDEA.
As to the real issue... You should be trying to dup(2) the filehandle since it is already open. But that won't work either. The tie() doesn't create a real filehandle in the OS sense of the term. It just lets you intercept calls to the mid-level Perl abstraction of a file handle. This is fine because the Perl abstraction is access via a known API. open(FH, "<-") is trying to open the REAL filehandle. Further, the Perl FileHandle TIE API doesn't provide functions for open() or dup() (interestingly it does provide CLOSE). So what is a perl-coder supposed to do? Well I don't know cuz you didn't show the real problem you are trying to solve and the assosiated code.
Where you have:
If you went all the way using the OO Perl file handle modules, you could have code that works this way: The above code style is the reason for the whole IO:: heirarchy (from my perspective). You can pass file handles into subroutines easily, and if those sub routines use file handles in either the OO-way or with <$fh> old-perl way it all works out as you expect. Please post an update, and we can help you further. P.S. Yes that pod2html() function from Pod::Html uses implicit inputs and outputs. See, that proves my point about subroutines with no inputs and ouputs. It restricts the flexability. It could have been pod2html($fh_pod_input, $fh_html_output). In reply to Re: Problem with tie *STDIN, 'IO::Scalar', \$text;
by LunaticLeo
|
|