On Thu, 17 Mar 2005 11:40:10 -0500, zentara wrote:
> >
> >{
> >....
> >$script = foo();
> >$output = `perl $script $a $b $c `;
> >do_someting($output);
> >...
> >}
> >
> >The above works fine , but I do not want to fork out a new perl process
> >every time. Is there a way I can avoid this. I would like to use do()
> >but how do I get the out from do();
>
> You might be able to use the piped form of open, but I find
> it easier to use IPC::Open3.
>
Since the original question was "I do not want to fork out a new perl
process", I don't see how your solution helps, as the open *will* fork
out a new process.
I do think that the "do" solution should work. For example, assume you
have a perl script called foo.pl where a single sub, foo(), is
defined:
################ foo.pl #############
use strict;
use warnings;
sub foo {
my $sum = 0;
$sum += $_ for (@_);
return $sum;
}
################ end foo.pl #############
Now from your calling script, all you need is:
################ calling_script.pl #############
my $name = "foo";
do "$name.pl";
my $result = foo(1,2,3); # must use the () version of calling foo!!
print "$result\n";
################ end calling_script.pl #############
See "perldoc -f do" for details of using "do EXPR".
Hope this helps,
--
Offer Kaye
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>