[EMAIL PROTECTED] wrote:
: I am writing a perl code which automatically forms a
: function name using certain criteria and then calls the
: same
It would probably be safer to use a hash table for that.
: I tired using the following code
: doesnt seem to work
:
: my $func = \&TEST3;
: if (! $func) {
: print "Function TEST3 does not exist\n";
: } else {
: print "TEST3 Function Exists\n";
: print &$func()." is return value\n";
: }
Try this. It basically checks for a CODE reference in the
symbol table for that function. I tested it in main::, but not
in a package. You can read more about it in "perlref" (item 7)
where *foo{THING} is described.
sub is_valid_function {
my $function = shift;
return ref eval("*$function\{CODE}") eq 'CODE';
}
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer
254 968-8328
Don't tread on my bandwidth. Trim your posts.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs