http://qs1969.pair.com?node_id=42943


in reply to how to use several modules by default?

In playing around to answer your question, I've found some interesting things:
[swiftone@swiftone /usr/local/src]$ perl -MData::Dumper -MText::Templa +te -e'print "hi"'
works fine.
#!/usr/bin/perl -w -MText::Template -MData::Dumper 1;
Bombs, because it tries to treat -MData::Dumper as part of the Text::Template call (in fact, anything after the first -M is thus treated. Alternate forms of -M listed in perlrun don't seem to change this)

Setting PERL5OPT acts as the second case. Does anyone know why?

Anyways, to answer your question, if you are going to go this route, define your own module that just loads the other modules you want. Then include that module via PERL5OPT

Replies are listed 'Best First'.
(tye)Re: how to use several modules by default?
by tye (Sage) on Nov 22, 2000 at 20:16 UTC

    The simple answer is that it is a bug in Perl.

    Looking at perl.c shows that PERL5OPT is mostly processed via PERL_moreswitches() which mentions:

    /* We allow -M'Module qw(Foo Bar)' */
    which seems strange. My guess is that PERL_moreswitches() was "enhanced" to allow this new usage by someone who didn't realize how this badly breaks #! and PERL5OPT.

            - tye (who wishes he had a revision-controlled copy of the Perl source)
      This isn't quite the same.

      -M'Module qw(Foo Bar)' is one argument. The space in there is held within the single quotes, so I wouldn't think this would have any effect on multiple -M flags, unless the implementation is broken (which I suspect is the case).

        Sorry, I wasn't clear and neither is the comment that I quoted. PERL_moreoptions() is passed a string (not, for example, a list of strings) and it doesn't handle quotes. What I meant to describe is that PERL_moreoptions() doesn't look for a new option after seeing a space after "-M" nor after "-m". Either that needs to happen or PERL5OPT needs to be split on whitespace and the resulting values passed ot PERL_moreoptions() one at a time.

        I would think that PERL_moreoptions() should be looking for spaces, otherwise it needs to be renamed PERL_onemoreoption().

        I'm sorry that this is a very quick reply as duty calls. Obviously more research is needed.

                - tye (but my friends call me "Tye")