in reply to use strict without typing use strict?

The only thing I could see at perlrun was the -M switch. For example:

> perl -c -Mstrict -e "my $fred = 42" -e syntax OK

> perl -c -Mstrict -e "$fred = 42" Global symbol "$fred" requires explicit package name (did you forget t +o declare "my $fred"?) at -e line 1. -e had compilation errors.

Replies are listed 'Best First'.
Re^2: use strict without typing use strict?
by LanX (Saint) on May 26, 2021 at 09:15 UTC
    Well in theory he could set the environment with PERL5OPT=-Mstrict or manipulate sitecustomize.pl (see perlrun for details) ...

    D:\tmp>set PERL5OPT=-Mstrict D:\tmp>perl -ce "$fred = 42" Global symbol "$fred" requires explicit package name (did you forget t +o declare "my $fred"?) at -e line 1. -e had compilation errors.

    ... but I would hate the side effect of random errors, if the script was accidentally run in another environment and strict was missing.

    The safest would be to alias/link perl to a new name like superl - the "super language" ;) - which auto-defaults to strict.

    Like this superl script.pl would simply not run if the workaround was missing.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    PS: On a side-note: The whole Perl7 mess could be solved like this too! (The language needs a rebranding anyway to overcome the mobbing. Don't shoot the messenger...:)

      Good catch. Totally forgot about PERL5OPT. :)

      Just in case this is an XY Problem, I'd be interested to learn the underlying real reason why the OP wants to do this. Just for personal convenience? Or is there an organisational back story, perhaps trying to control what others do?

Re^2: use strict without typing use strict?
by hippo (Archbishop) on May 26, 2021 at 09:23 UTC

    If you wanted to use that all the time, then PERL5OPT is one solution:

    $ export PERL5OPT='-Mstrict' $ perl -e '$x = 1; print qq{$x\n}' Global symbol "$x" requires explicit package name at -e line 1. Global symbol "$x" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. $

    🦛

      One caveat to keep in the back of your mind if you dabble with PERL5OPT: every arbitrary perl you may run will see that and (try to) honor it. At $work we've got some stuff therein that works fine when run with our separate application copy of a newer version, but woe be unto the person that manages to mungle their PATH and instead wind up getting the (long in the tooth) OS' /usr/bin/perl instead because there's modules pulled in which have a newer use 5.xx constraint and there's much errors and blowing up and the not running (GLEIVEN!</bad professor frink>).

      Probably not an issue WRT just a PERL5OPT="-Mstrict" but be aware of that limitation if you start getting fancier.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.