Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Re: Problem with tie *STDIN, 'IO::Scalar', \$text;

by Rudif (Hermit)
on Apr 29, 2001 at 15:34 UTC ( #76462=note: print w/replies, xml ) Need Help??

in reply to Re: Problem with tie *STDIN, 'IO::Scalar', \$text;
in thread Problem with tie *STDIN, 'IO::Scalar', \$text;

Well I don't know cuz you didn't show the real problem you are trying to solve and the assosiated code.

pod2html() function from Pod::Html uses implicit inputs and outputs.
It could have been pod2html($fh_pod_input, $fh_html_output).

But it is not, and hence my problem.
I want to feed text from a scalar variable to a subroutine that reads from STDIN. Specifically, I want to convert some pod text from a scalar variable to a html file, using Pod::Html::pod2html.

This here does the job, but it uses a script that wraps the sub Pod::Html::pod2html:
sub string2Html { my ($htmlfilename, $podtext) = @_; open PIPE, "| pod2html --outfile $htmlfilename"; # works, because there is a pod2html.bat print PIPE $podString; close PIPE; }
I would like to replace it by something like this, not using a separate script and pipes or temporary files:
sub string2Html { my ($htmlfilename, $podtext) = @_; ### some code that causes pod2html to read from scalar \$podtext; ### when it wants to read from STDIN Pod::Html::pod2html "--outfile $htmlfilename"; ### code to wrap up }
I hope that this clarifies what I am trying to solve.


Replies are listed 'Best First'.
Re: Re: Re: Problem with tie *STDIN, 'IO::Scalar', \$text;
by LunaticLeo (Scribe) on Apr 30, 2001 at 20:18 UTC
    Thanks for the clarification. I should have read your original post more thoroughtly.

    I tried all my tricks to fake out &Pod::Html::pod2html, but I can't make it work without resorting to pipes.

    If you wish to resort to pipes, the following Worked For Me(tm).

    use strict; use IO::File; use IO::Pipe; use Pod::Html qw( &pod2html ); # I only use $fh to get a pod string, It is not part # of the solution. my $fh = IO::File->new("<foo.pod") or die "filaed to open foo.pod: $!"; $fh->input_record_separator( undef ); my ($str); $str = $fh->getline(); $fh->close; # Got the pod string in $str my $pipe = IO::Pipe->new() or die "failed to create pipe: $!"; my ($pid,$fd); if ( $pid = fork() ) { #parent open(TMPSTDIN, "<&STDIN") or die "failed to dup stdin to tmp: $!"; $pipe->reader(); $fd = $pipe->fileno; open(STDIN, "<&=$fd") or die "failed to dup \$fd to STDIN: $!"; pod2html(); open(STDIN, "<&TMPSTDIN") or die "failed to restore dup'ed stdin: $!"; } else { #child $pipe->writer(); $pipe->print($str); $pipe->close(); exit 0; } $pipe->close(); exit 0;

    I think this will work satifactorally even on the Win32 port of Perl. Win32 doesn't really fork(), it just creates a thread. But I restore the original STDIN and the child dies pretty quickly.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://76462]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2020-09-25 22:33 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (141 votes). Check out past polls.