Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

how to use several modules by default?

by princepawn (Parson)
on Nov 22, 2000 at 19:12 UTC ( #42939=perlquestion: print w/ replies, xml ) Need Help??
princepawn has asked for the wisdom of the Perl Monks concerning the following question:

Hi, thanks to the tutelage of people here, it is clear that any robust programmer should always use strict, warnings, and perldiag. Thus I want to always load these by default. How can I set up Perl/my environment to do so?
PERL5OPT="-Mstrict -Mwarnings -Mdiagnostics"
only honours the first -M option. The others are ignored.

Comment on how to use several modules by default?
Download Code
Re: how to use several modules by default?
by merlyn (Sage) on Nov 22, 2000 at 19:14 UTC
    Setting that up in your environment won't help others who are invoking your programs. I suggest you get a text editor that has a templating feature. I could suggest a very popular one, but then we'd start a religious war here. {grin}

    -- Randal L. Schwartz, Perl hacker

      >Setting that up in your environment won't help others who are invoking your programs.

      Unless you're serious about having `debug' and `release' versions of your programs. In theory, there shouldn't be any need for non-developing users to activate strictness or diagnostics, or even warnings, right? In practice, it won't hurt them to have to do this manually anyway.

      IMHO, of course.

Re: how to use several modules by default?
by swiftone (Curate) on Nov 22, 2000 at 19:33 UTC
    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

      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).

Re: how to use several modules by default?
by KM (Priest) on Nov 22, 2000 at 21:36 UTC
    A workaround for this would be:

    PERL5OPT="-Mstrict; use warnings; use diagnostics;"

    Cheers,
    KM

Re: how to use several modules by default?
by Dominus (Parson) on Nov 24, 2000 at 00:21 UTC
    Oh, you're right. That is a bug.

    I reported it on p5p and Simon Cozens contributed a patch so it should be fixed by 5.6.1.

    I realize that that doesn't help you much. What I suggest you do is make up a file called PrincePawn.pm that looks like this:

    # PrincePawn.pm use warnings; use diagnostics; # and others... 1;
    Then use PERL5OPT="-MPrincePawn".

    Unfortunately, this does not work for strict, because strict has only a lexical effect.

Re: how to use several modules by default?
by ColonelPanic (Friar) on Nov 28, 2000 at 00:04 UTC
    Well, using -w for warnings would cut the problem in half, right? Another thought: Have you tried
    -M'strict'
    ? That could fix the problem, too.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://42939]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2014-08-21 06:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls