in reply to Backdating strict

> Is there any benefit to going back over working code, breaking it and having to repair it again to include this pragma?

Yes. If you have a pesky block that you can't "fix" then use a lexical block scope to turn off strict where needed.

Replies are listed 'Best First'.
Re^2: Backdating strict
by tobyink (Canon) on Nov 19, 2020 at 01:49 UTC

    The inverse is true too.

    If you've got a long script and you don't feel ready to convert the whole thing over to strict, you can switch it on for a particular sub:

    sub do_stuff { use strict; ...; }

    If your script is working fine as-is, leave it alone. If you notice a bug in a sub or need to add a new feature to a sub, then switch on strict for just that sub while you're making your improvements, and then leave it on for that sub. Over time, more and more of your script will become strict. Once most of the file seems to be strict, then making the whole file strict will be a much smaller task.

      That does sound like the best way forward for me...enforce strict initially one subroutine at a time then one lexical block at a time until the complete code unit has strictures enforced.

      Quick question...
      If I have use strict; followed by a require statement in the same block, does the code that is brought in by the require have strict applied to it - my guess is yes as it is in the same lexical block.

      I can't test it right now as I am using my mobile and AFAIK there isn't a version of Perl for Android.

        No, code brought in with use or require is its own top-level lexical scope.

        Explained differently, lexical scopes do not cross file boundaries in Perl; the loading mechanism is not a preprocessor.

        If this were not so, the common convention of making use strict; the first statement in a script would also apply strict to all library modules, but this does not happen.

        I've not used this in a while, perhaps worth checking out.

      then switch on strict for just that sub while you're making your improvements

      I suppose that use strict; makes the reset keyword obsolete.