On Thu, 17 Mar 2005, Ramprasad A Padmanabhan wrote:

>   I have a requirement to call a perl script within another and take 
> the output

Okay. 

The typical way to do this would be to make a module out of it, or at 
least a "require" call, but it looks like you may be generating the code 
dynamically rather than just running the contents of another file.

That's fine, Perl can do that, too.
 
> for example 
> 
> { 
> ....
> $script = foo();
> $output = `perl $script $a $b $c `;
> do_someting($output);
> ...
> }

No. Don't do it that way, that's just silly :-)

If the code for $script is being generated by the foo() subroutine, then 
why are you not just eval()ing on the spot?

    {
        $script = foo();
        $output = eval{ $script } or
            die "Couldn't eval code: $script\n$!\n";
        do_something($output);
    }

There's no reason to go out and call Perl again; you already have a 
perfectly good Perl interpreter running where you are at this point :-)

 

-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to