You are correct chromatic, I needed to use a named lexical there. Not really sure why that is. This works:

use Symbol 'delete_package'; foreach my $module (@modules) { require "sub/$module.pm"; import $module qw(foo bar); foo(); bar(); #cleanup delete_package($module); }

As well as the function call format that you wrote it in.

strict; system('rm -fr /home'), lol! tobyink, the modules are all created by myself so I'm (reasonably) sure that nothing like that will every happen. Thanks for looking out for me, though =D

use Symbol 'delete_package'; foreach my $module (@modules) { eval "use sub::$module"; import $module qw(foo bar); foo(); bar(); #cleanup delete_package($module); }

Works fine as well.

CountZero, cool little module. That does the trick too:

use Symbol 'delete_package'; require UNIVERSAL::require; foreach my $module (@modules) { "sub::$module"->require or die $@; import $module qw(foo bar); foo(); bar(); #cleanup delete_package($module); }

Thanks guys!

Strange things are afoot at the Circle-K.


In reply to Re: require & import $module_name by temporal
in thread require & import $module_name by temporal

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.