#Require the file with the function definitions. #Use eval to catch errors. eval { require "definitions.pl"; }; #__PACKAGE__ is a token that gets replaced with the #name of the current package. You must not quote it. #Why? Because Perl said so. my $package = __PACKAGE__; #Add a 'can' test to each function call... #This is the shortest. It uses object-oriented #calling syntax: top() if $package->can('top'); #If you don't like dangling if's, try this: if ($package->can('middle')) { middle(); } #This short-cuts the object-oriented calling syntax, #and uses the relatively obscure UNIVERSAL package #directly. #IMO it's really messy, but it's technically the fastest. end() if UNIVERSAL::can($package,'end');
Hope this helps!
Jerry
Edit: chipmunk 2001-03-29
In reply to Re: Calling a function that may not be there...
by Benedictine Monk
in thread Calling a function that may not be there...
by Hammy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |