Your question is a little confusing, but I will do my best. It seems like you are trying to see if certain functions have been exported into your main script.
First step, read up on packages. Your script should have the package name 'main' (you might even want to get in the habit of specifying package main;). Once you realize this, you can use the standard method for checking to see if a package has a particular method/subroutine available.
All packages are descendants of UNIVERSAL, so you can use its can method, which looks like this:
PackageName->can('sub_name');
So, if you're in the main package:
$PAGE = "test_function_a"; eval "$PAGE" if main->can($PAGE);
However, this is probably not what you want to do. Executing function names stored in variables can be rather dangerous, and you should understand the risks before doing so. I don't know what problem you're trying to solve, but perhaps a solution like a rudimetary dispatch table is better suited:
my %dispatch = ( 'test_function_a' => \&test_function_a, 'test_function_b' => \&test_function_b, ); foreach my $func ( qw'test_function_a test_function_b' ) { die "Package main doesn't seem able to '$func'" unless main->can($f +unc); $dispatch{$func}->(); }
This avoids some of the issues with eval, and might even be faster.
In reply to Re^3: Loading all files in a dir with use via for loop
by radiantmatrix
in thread Loading all files in a dir with use via for loop
by Delusional
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |