Rudif has asked for the wisdom of the Perl Monks concerning the following question:
Now I want to achieve the opposite: feed text from a scalar variable to a subroutine that reads from STDIN.my $podfile = "some.pod"; my $scalar = ''; tie *STDOUT, 'IO::Scalar', \$scalar; podselect $podfile; # reads form $podfile, writes to STDOUT untie *STDOUT; # now $scalar contains the pod from $podfile
but it does not work as I expected. Am I doing something wrong, or is this a limitation of IO::Scalar?my $scalar = "some pod text"; tie *STDIN, 'IO::Scalar', \$scalar; pod2html; untie *STDIN; # reads from 'real' STDIN, not from $scalar
#! perl -w use strict; use Pod::Html; use IO::Scalar; $|++; my $text = <<EOT; =head1 TESTING First line Second line Third line =cut EOT # these work tieAngle(); pipePod2html(); # these do not work tiePod2html(); tieOpenDash(); sub tieAngle { print "\n=1 tieAngle================================== OK\n"; tie *STDIN, 'IO::Scalar', \$text; while (<STDIN>) { print "=1=$_"; } untie *STDIN; } sub pipePod2html { print "\n=pipePod2html================================== OK\n"; open PIPE, "| pod2html"; # works, because there is a pod2html.bat print PIPE $text; } sub tiePod2html { print "\n=tiePod2html================================== NOT OK\n"; tie *STDIN, 'IO::Scalar', \$text; pod2html; untie *STDIN; } sub tieOpenDash { print "\n=3 tieOpenDash================================== NOT OK\n +"; tie *STDIN, 'IO::Scalar', \$text; # similar to what pod2html does: open TSCLR, "<-" or die "can't open <-"; while (<TSCLR>) { print "=3=$_"; } close TSCLR; untie *STDIN; } __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with tie *STDIN, 'IO::Scalar', \$text;
by chromatic (Archbishop) on Apr 29, 2001 at 01:45 UTC | |
by Rudif (Hermit) on Apr 29, 2001 at 19:04 UTC | |
|
Re: Problem with tie *STDIN, 'IO::Scalar', \$text;
by LunaticLeo (Scribe) on Apr 29, 2001 at 08:38 UTC | |
by Rudif (Hermit) on Apr 29, 2001 at 15:34 UTC | |
by LunaticLeo (Scribe) on Apr 30, 2001 at 20:18 UTC | |
by Clownburner (Monk) on Apr 30, 2001 at 01:14 UTC | |
by LunaticLeo (Scribe) on Apr 30, 2001 at 20:36 UTC |