in reply to Re^2: Perl logical operators
in thread Perl logical operators

We went through all that more than a decade ago: Why isn't C<use strict> the default?

Replies are listed 'Best First'.
Re^4: Perl logical operators
by roboticus (Chancellor) on Jul 18, 2018 at 17:32 UTC

    hippo:

    Yeah, but I'd really like to see it become the default.

    Were I to do it, I'd make strict/warnings default, and provide an environment variable to control it. Something like:

    PERL5STRICT:
    • When set to 0, use current (legacy) behavior: you must use strict/warnings if you want them, no warnings if you omit them.
    • When set to 1, automatically use strict/warnings, no warnings if you have them or if you omit them.
    • When unset, automatically use strict/warnings, print a warning (mentioning the PERL5STRICT environment variable) if you include use strict/warnings. Something like:
      Line ##: use strict found, but strict/warnings are on by default. (See PERL5STRICT in ENVIRONMENT section in perlrun for details)

    My second preference (should people dislike the idea of changing the default behavior even with a global override) would be to use this behavior if you invoke perl as perl5, and when you invoke it as perl it would do as it does currently (i.e., act as if PERL5STRICT is 0). That way, I could just link perl to perl5 and change my typical shebang line to:

    #!env perl5

    Hmmmm .... I wonder if they would accept a patch? I doubt it would be very difficult, and I currently have some free time on my hands.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      From my perspective I don't want it to be a plain default. I use Perl on the command line a great deal and having to type "my" and such "just because" would be a small burden but one that would add up quickly to be extremely irritating; irritating to the point of exploring other languages to see if they were less of a hassle. There may be some middle ground where -e turns off strict or any scope change turns it on or something(?).

      What haukex said about use {version} and backwards compatibility is germane I think.

        Your Mother:

        Having -e automatically disable strict/warn certainly sounds reasonable.

        I also either forgot (or didn't notice) that "use 5.12.0" would enable strict. On the bright side, that'll give me a couple things to look at to see how to implement such a feature. But since I've n ot put enough time into thinking about the various ramifications, I'll have to chew on it a bit longer. I'll also have to review the various perldeltas and see what other things I've missed. ;^)

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

      Perl5opt is already provided for that explicit purpose. PERL5STRICT is dumb.

        Nice! I really ought to review all the perl docs again and see what other interesting things I've missed.

        I just gave it a try, and it seems to work well. I went ahead and updated my .bashrc file:

        . . . export PERL5LIB="/mystuff/Perl/LIB" export PERL5OPT="-Mstrict -Mwarnings" alias p5="perl -Mstrict -Mwarnings" . . .

        and now have the behavior I want. Pretty nice.

        The PERL5OPT setting might interfere with some other scripts (I won't know until I run into one of them), so I created an alias to do essentially the same thing. (I wonder why I haven't thought of that earlier?) I'll remove the PERL5OPT setting if/when it causes me any grief. As Your Mother mentions earlier, it's often going to be a problem for one-liners. I rarely use one-liners, but I don't know how many are embedded into many of the tools I use.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.