Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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
    [Corion]: Meh. Once again I find that SQLite doesn't support window functions and I want to use those nowadays :-)
    [erix]: Look what I found! :P
    [Corion]: Hmm - actually, I don't need them, even though they'd be nice. I just want the (say) 10 latest images, and that's easily done with a limit 10 offset 0 clause, as I don't need all top 10 images for all users.
    [Corion]: erix: Sure, but this is for a really-lightweight application and I'm replacing a CSV file / JSON file for user configuration with SQLite (and optionally, Pg) :)

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (10)
    As of 2018-03-20 13:58 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (253 votes). Check out past polls.