Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Loading modules by external data (i.e., database)

by theatrus (Initiate)
on Jun 04, 2000 at 09:45 UTC ( #16270=categorized question: print w/replies, xml ) Need Help??
Contributed by theatrus on Jun 04, 2000 at 09:45 UTC
Q&A  > object-oriented programming


I'm attempting to create a module which loads a Perl module by name. So a database has a list of modules by a more friendly name, and a script calls the loader function to load the actual module and return an object. Example of what I'm trying to do: sub load($module) { if ($nett_load_hash$module == 0) { use vars qw($module); $nett_load_hash$module = 1; } return $module->new(); } Obviously, it doesn't work at the 'return' part. How would I do this? PHP works nicely by loading "modules" ($module = new $name). Anything like this in Perl?

Answer: Loading modules by external data (i.e., database)
contributed by Corion

In my (frozen) file information display tool (a souped up magic program), I used dynamic loading for modules more or less like this :

$handler = eval( "use $modulename; return $modulename->new;" );
(I'm in a hurry, if this one dosen't work, tell me and I'll look up the actual code :))

Answer: Loading modules by external data (i.e., database)
contributed by chromatic

I have a Unixy solution in Building a Simple Perl Module Database. Something there might help.

Please (register and) log in if you wish to add an answer

  • 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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (3)
    As of 2020-09-19 22:47 GMT
    Find Nodes?
      Voting Booth?
      If at first I donít succeed, I Ö

      Results (116 votes). Check out past polls.