Hi, I'm trying to load a module at runtime and then accessing a variable within that module. Loading the module and importing the symbols seems to work fine, but I'm having difficulty with the syntax of accessing the variable.
my $module_name = sprintf "Plugin::",$plugin_name; eval "require $module_name"; die if $@; $module_name->import(); print "Plugin $module_name describes its purpose as:\n"; #syntax problem in the following line print $module_name->description, "\n";

$module_name->description obviously tries to invoke a subroutine called description in the relevant package.

$$module_name->description or ${$module_name}->description would act as if $module_name was a ref.

I'm a bit at a loss here. What would the correct syntax be? (Is there a correct syntax, or would I be forced to interact with the plugins through routines?)

Thanks in advance!


In reply to Accessing variables in a runtime-loaded module by srd

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.