Ok, you can't specify which module to load via @ARGV with use. use basically works its magic at compile time, and has already done its thing before $ARGV[0] is ever determined.

You might be able to do it with require. The documentation for use states the following:

It (use) is exactly equivalent to

BEGIN { require Module; import Module LIST; }

Please consider using variables other than $a and $b. Those variables have special meaning inside sort routines, and you'll create potential for all sorts of havoc if you steal them for your own use.

You know, Perl actually already offers you a better solution anyway. If your need is to supply the module name on the command line, don't rely on @ARGV. Instead, use Perl's command line switch, "-M", like this:

perl -MFoo myscript.pl

See perlrun for details.

An update:
You can probably still use -M even if your module resides along a path not specified in @INC. You can deal with this difficulty using either the -I[directory] switch, or the -f switch, which are also documented in perlrun.


Dave


In reply to Re: modules as variables by davido
in thread modules as variables by tcf03

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.