On Thu, 17 Mar 2005, Ramprasad A Padmanabhan wrote:
> > 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);
> > }
>
> I am sorry for having created the confusion.
> foo() returns the filename of the script
Okay, so we're back to my other suggestion -- "require" it:
{
$script = get_name_of_script(); # names matter! pick good ones!
$output = require $script or
die "Couldn't 'require' $script\n$!\n";
do_something($output);
}
There's still no need to call on a second instance of perl for this.
> Now can I do this without a diff interpreter. would you suggest I read
> the file into a string and eval it
I think that may be substantially what "require" does, but for most
purposes you shouldn't have to worry about how it's implemented -- just
call it, run your script, and go back to what you were doing.
--
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>