I have a situation where I'm working on a module loader, that will be passed names of other Perl modules, or .pl packages, and optional release version numbers, that may or may not be in a standard Perl library path. The module's import method will look at each module name passed to it in it's LIST, and look through a series of known non-standard directory paths for that versioned module file. So the interface is something like:
# This is the location where the loader module will be # picked up. use lib qw( /net/public/tools/perl/lib ); use PmLoader qw( MyFunnyModule :1.5 someoldpackage.pl Some::Hierarchical::Module :2.1 );
The PmLoader will parse the module name, and a version number (if it exists) for that module. Otherwise, it will query our system to see if there is a "current" version for this modulename, and use it. Now these funny modules may be located in paths down from /net/public/tools/perl/lib that may contain the version number in the path, or the module name as a parent directory, in a known set of subdirectories. (These are the result of many years of haphazard development and installation methods.) For example:
/net/public/tools/perl/lib/MyFunnyModule/<version>/MyFunnyModule.pm /net/public/tools/perl/lib/MyFunnyModule/MyFunnyModule.pm,<version> /net/public/tools/perl/lib/pl-libs/someoldpackage.pl
But basically, after the PmLoader.pm module has found each of the correct modules (or .pl files), and pushed that path on @INC, I then need to load the module. So here's the rub: I need to do this:
BEGIN { require $module; }
Perl really doesn't like that variable name however in the BEGIN require block!! First of all, the variable $module set in the PmLoader sub import routine, isn't visible to the BEGIN{} block. And secondly, even if it was, I don't think it like seeing a variable there. What's the solution to loading module names that exist in variables?? -Cadphile

In reply to use/require $MODULE (a variable) by cadphile

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.