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.

<-radiant.matrix->
Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.