ViceRaid has asked for the wisdom of the Perl Monks concerning the following question:

Afternoon

Is there any way to specify that strict should be enforced by passing an option on the command line, or do -m / -M not apply at all to pragmata? I'm thinking of something analogous to -w and use warnings.

With thanks
ViceRaid

Replies are listed 'Best First'.
Re: perl -mstrict foo.pl
by djantzen (Priest) on Jun 06, 2003 at 16:32 UTC

    perl -Mstrict script.pl works for me.


    "The dead do not recognize context" -- Kai, Lexx
Re: perl -mstrict foo.pl
by DamnDirtyApe (Curate) on Jun 06, 2003 at 16:33 UTC

    Seems to work fine for me...

    (~) $ perl -Mstrict -e '$foo = 'bar'; print $foo . $/;' Global symbol "$foo" requires explicit package name at -e line 1. Global symbol "$foo" requires explicit package name at -e line 1. Bareword "bar" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors.

    Update: Wow, still to early in the morning for me. Still, when I fix my quotes, I get the same basic results:

    (~) $ perl -Mstrict -e '$foo = "bar"; print $foo . $/;' Global symbol "$foo" requires explicit package name at -e line 1. Global symbol "$foo" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
Re: perl -mstrict foo.pl
by Tomte (Priest) on Jun 06, 2003 at 16:33 UTC

    normaly:

    tom@margo:~> perl -e 'print $test'; tom@margo:~>

    Enforce strict

    tom@margo:~> perl -Mstrict -e 'print $test'; Global symbol "$test" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

    Or did i misread your question?

    regards,
    tomte


    Hlade's Law:

    If you have a difficult task, give it to a lazy person --
    they will find an easier way to do it.

      Yes, thank you, you've all understood my question right. There must be something else going on ... something fishy ... something embarrassing ...

      alexf@localhost ~ $ perl -Mstrict -e 'print $a' alexf@localhost ~ $

      Doubly embarrassing, looking back to Feb 2002, I once advised a soul facing exactly this puzzler.

      Yours, sheepishly
      ViceRaid

        Update: realized too late that you understood the reason, nevertheless may this answer stand here for others as slow as myself in understanding written english :)

        perldoc perlvar :)

        $a $b Special package variables when using sort(), see "sort" in perlfunc. Because of this specialness $a and $b don't need to be declared (using local(), use vars, or our()) even when using the strict vars pragma. Don't lexicalize them with "my $a" or "my $b" if you want to be able to use them in the sort() comparison block or function.

        regards,
        tomte


        Hlade's Law:

        If you have a difficult task, give it to a lazy person --
        they will find an easier way to do it.

        Oh, ha! $a and $b are global variables used by sort and so are already known by perl. That's why you don't see any errors in your example.


        "The dead do not recognize context" -- Kai, Lexx