I inherited some perl code that of course doesn't use either strict or warnings, and I keep using uninitialized variables and the like.
I'd like to bracket the sections of code that I'm modifying like this:
use warnings;
use strict;
... my code changes and additions ...
no strict;
no warnings;
And that seems to work, but I'm having issues deciphering what the perldoc on use means when it says these are compiler directives that import into the current "block scope." Does that mean that any scope can have a use strict
unpaired with a no strict
? Is the no strict
at the tail of the global scope essentially undoing the meaning of use strict
earlier in the same scope?
use strict
of course doesn't also allow easy code encapsulation... I have to add to their eleventytwo global hashtables, you see...%main::blah
(assuming it's in package main). Even better, pass their globals you need to modify into your subroutines by reference:some_new_sub(\%blah)
. It will prevent their global mess from infecting new code. This will be messy at first, but it will give you a better idea of what code needs what data. Through all this, the Extract Method pattern will be your strongest tool.