Newbie dot Org HomePage
Visit one of our web buddies
Newbie dot Org
Code Snippets

On the path to proper Perl -- use strict

It is all too easy for webdevelopers with a need to "just get that darn script to work" to fall into the trap of not learning proper Perl.

One (of several) sure fire ways to put yourself on the path to proper Perl coding is through the use of use strict;

use strict;
See the "use strict;" line right below the top shebang line? That will enforce some very handy error checking. It will make sure you don't use a variable that is not declared. You must predeclare a variable. And, you either have to fully qualify a variable (such as $packagename::varname), import it the variable (such as happens with use or 'import'), or specifically tell the processor that you want this variable to be used as global (such as use vars ('%formdata'); You can learn more about this from the various books on Perl. That is if you get a book on programming Perl not a book on "how to get by without learning much." "use strict;" will also make sure you don't fall into the bad habit of using barewords to call a subroutine. If you want to use a bareword (which I don't recommend) to call a subroutine you are forced to predeclare the subroutine. Once again you are forced to either do it right or know what you are doing to get around the rules. It will make sure you do stuff on purpose. Maybe you won't want to use strict on your very first script.... Go ahead and use it. It will start you on the road to proper Perl programming and when you ask for help from professional programmers they won't look down their collective noses at you so much -- since you are making the effort to learn Perl rather than "just get by".

Posted by Xxaxx on 04/28/01 at 01:56:33