http://qs321.pair.com?node_id=76409

Rudif has asked for the wisdom of the Perl Monks concerning the following question:

Ave!

stephen showed us recently here how to capture into a scalar variable the output that a Perl subroutine, such as  Pod::Html::pod2html or  Pod::Select::podselect, writes to  STDOUT :
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
Now I want to achieve the opposite: feed text from a scalar variable to a subroutine that reads from STDIN.
Is it possible, and how could I do it?

I tried this
my $scalar = "some pod text"; tie *STDIN, 'IO::Scalar', \$scalar; pod2html; untie *STDIN; # reads from 'real' STDIN, not from $scalar
but it does not work as I expected. Am I doing something wrong, or is this a limitation of IO::Scalar?

My script below shows the following: where 'does not work' means that it does not read from my scalar but from the real STDIN.

My platform is Win2k and perl is 5.6.0, AS build 623.

Rudif
#! 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__