Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Backdating strict

by tobyink (Canon)
on Nov 19, 2020 at 01:49 UTC ( [id://11123809]=note: print w/replies, xml ) Need Help??


in reply to Re: Backdating strict
in thread Backdating strict

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.

Replies are listed 'Best First'.
Re^3: Backdating strict
by Bod (Parson) on Nov 19, 2020 at 17:14 UTC

    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.

        Thanks marto - that looks rather interesting!

        I was right...it is very interesting and now I have a newer version of Perl - 5.32 on my mobile than I do on my laptop or webserver!!! Somehow that doesn't seem quite right but some things are best left unquestioned :)

        Thanks for the information marto

Re^3: Backdating strict
by Bod (Parson) on Nov 30, 2020 at 23:01 UTC

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

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

        I can't recall having ever used reset

        I used to regularly use reset at the end of loops to clear variables that were just being used in that loop - but now I use my instead which, I believe, is better practice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-25 15:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found