I think I may have done something similar to what you want here. The basic idea is to create a new instance of an object at runtime, as opposed to compile time.

My solution uses file::find to go out and search for modules, then create a new instance of them.

The literal idea is to be able to create new modules to do different tasks, so you can bounce the server, and it will pick up the new modules automatically. Each module has the same method names, so the main object doesnt have to be aware of any extra method names..

Anyways, back to the main point, the code snippet i settled on puts a new instance of an obects into $self, based on a variable passed to the method.

I'm not sure why this would be a maintaince nightmare as merlyn suggested, as the code is self explanitory and the "unknown" modules are in a central repository - perhaps i've missed the point somewhere along the way...


In reply to Re: dynamically creating variables named after the contents of an array by Ryszard
in thread dynamically creating variables named after the contents of an array by gnu@perl

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.