PBP: 053 Localization

The PBP tells us to localize changes to package variables.  This is usually good sense, and prevents your changes from leaking out and messing with other things.

I’ve mentioned this in another entry, because it was natural and fit there.  If you have to change these values, change them.  That’s what they’re for.  Try and keep your change as limited in scope as possible.  That’s what Perl’s odd but handy “local” keyword does.  Use it in good health.

I also mentioned before that perlcritic is sometimes overly picky about this.  There are some things you’re changing and the point is to change them.  You as the engineer know best; shut off the robot’s warning this time, and make your change.

I think doing this automatically is one of the signs of a really experienced and mature Perl engineer.

Leave a Reply