On Fri, 24 Aug 2001, Christopher Solomon wrote:
> On Fri, 24 Aug 2001, Michael Dube wrote:
>
> > Hi,
> >
> > I have a script that uses require to include additional perl scripts at
> > runtime. I would like to call a function if and only if that function is
> > defined in the required module. How would this be done? Would the define()
> > function work? Here's some pseudo of what I intend... any ideas?
> >
> > require runtime.pl;
> >
> > if (defined(runtimefunction)) {
> > runtimefunction(args);
> > }
>
> Can you elaborate why you wouldn't know if the function is present or not?
>
>
> Probably the best way is to use an eval block to see if the function can
> execute.
>
> Check out The Camel's extensive sections on eval(). I don't have the book
> on me, so I can't quote you the pages....
>
Ooops, I meant to include a crude example. Here's the general idiom:
eval {
function_foo();
};
$@ ? warn "function_foo not called!" : function_foo();
$@ will be true if the eval raises a syntax error.
hope that helps,
Chris
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]