in reply to Problem with tie *STDIN, 'IO::Scalar', \$text;
As to the real issue...
You are tie'ing a scalar to the global symbol for the STDIN filehandle. Then you try to open the real STDIN using a trick perl provides. Even if your method could work, which it won't, It is a BAD IDEA(tm) to open a file handle twice.
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:
open TSCLR, "<-" or die "can't open <-";
you could replace it with:
local *TSCLR = \*STDIN;
This works at the name space level.
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.use IO::File (); use IO::Scalar (); sub do_stuff_with_a_fh { my ($fh) = @_; ...do stuff... } my $str = "this is my string"; my $fh_scalar = IO::Scalar->new(\$str) or die "failed to create fh from str: $!"; do_stuff_with_a_fh($fh_scalar); my $fh_stdin_duped = IO::File->new("<&STDIN") or die "failed to dup stdin: $!"; do_stuff_with_a_fh($fh_sdtin_duped);
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).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Problem with tie *STDIN, 'IO::Scalar', \$text;
by Rudif (Hermit) on Apr 29, 2001 at 15:34 UTC | |
by LunaticLeo (Scribe) on Apr 30, 2001 at 20:18 UTC | |
|
Re: Re: Problem with tie *STDIN, 'IO::Scalar', \$text;
by Clownburner (Monk) on Apr 30, 2001 at 01:14 UTC | |
by LunaticLeo (Scribe) on Apr 30, 2001 at 20:36 UTC |