in reply to Calling a function that may not be there...

By far the easiest way to do this is to use can():
#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

Replies are listed 'Best First'.
Re: Re: Calling a function that may not be there...
by Anonymous Monk on Mar 27, 2001 at 09:57 UTC
    You don't need a temporary variable. Just use __PACKAGE__->can('subname')