So as I understand it, you want to get the string printed by the subroutine into a variable in the calling namespace. If this is what you want try something like this:
use IO::Pipe; use strict; my $pipe = IO::Pipe->new(); if(my $pid = fork()){ waitpid($pid, 0); $pipe->reader(); my $str = <$pipe>; print "\$str == '$str'\n"; }else{ $pipe->writer(); &print_to_pipe($pipe); } sub print_to_pipe { my $fh = shift; print $fh "Hello World\n"; }
See IO::Pipe.
In reply to Re: Can a string be a file hanle?
by JediWizard
in thread Can a string be a file hanle?
by johnnywang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |