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

A month or so ago, I replied to Implementing strict on shoddy code with a potential solution to adding strict piecemeal by using requires.(Re: Re:(2501- further clarification) Implementing strict on shoddy code) In short, I found that if I use strict in one script, and then require a separate one, strict does not carry over, other than hiding the variables of the parent script.

My question now is whether writing my new code inside a required script using strict is a valid solution to slowly bringing everything into using strict?

I am currently in a situation where I am working on a large project (20,000+) lines of code. This code, after it's release, will be a continual evolution of bug fixes and added features. None of the code uses strict, as of yet. As I am now adding additional functionality, I have the opportunity to use strict on anything I write, and potentially correct some of the other code as time permits. Because of the amount of preexisting code, and time constraints, I cannot just drop use strict at the top and hope to finish anywhere near the deadline.

Thanks for your help

Replies are listed 'Best First'.
Re: Partial strict using require
by chipmunk (Parson) on Feb 28, 2001 at 23:39 UTC
    The reason you see this behavior is that use strict is a lexical pragma. It is in effect only for the scope in which it occurs, either a block or a file.

    It is important to understand that strict does not hide variables. Declaring variables with my(), which makes them lexical, hides the variables. It is true that using strict requires you to declare your variables. However, variables can also be declared as package variables with use vars, and variables can be declared with my() to hide them whether or not strict vars is in effect.

    Instead of separating your code into different files, some with strict and some without, you could separate your code into separate blocks in the same file, as in:

    { use strict; # some strict-compliant code } # some non-strict compliant code
Re: Partial strict using require
by tadman (Prior) on Feb 28, 2001 at 23:52 UTC
    There doesn't appear to be a way to force perl to be strict about all your code, but there is an easy way to work through it incrementally. What you could do is test each module, fix any serious errors, and then catch the minor ones later when you have time.

    You can "test" the modules by running them, such as:      % perl -w -Mstrict Some_Module.pm This will generate a whole bunch of errors and warnings, or, if things are cool, it will presumably do nothing at all (unless the module actually does something by default). Once you're done, or merely tired of fixing all the bloody errors, you can just run the program normally, whatever that means.