1. Computing

Why you should 'use strict'

By September 21, 2006

If you're serious about developing in Perl and not just firing off scripts and forgetting them, you should be starting every Perl program with these lines:
#!/usr/local/bin/perl -w
use strict;
This will help you (really, it will force you) to write better, cleaner code. Adding the -w switch to the perl interpreter will cause it to spit out warnings on uninitialized variables - potential bugs. 'use strict' turns on the 'strict' pragma which will make you declare your variables with the my keyword. 'use strict' also tosses up errors if your code contains any barewords that can't be interpreted in their current context.

Start using those two lines, even if it seems like extra work. The payoff comes in the form of code that is more easily maintained. You can read more about 'use strict' in the Beginners Intro to Perl tutorial from Doug Sheppard on Perl.com

Beginners Intro to Perl - use strict
Comments
September 26, 2006 at 1:05 pm
(1) Richard says:

I’m glad you brought this up… clean programming = less headaches.

There are other “use” pragmas that are also useful:

use integer;
use lib;
use sigtrap;
use subs;
use vars;

With some of these you can also use the “no” declaration such as:

no integer;
no strict `vars`;

Thanks, Kirk.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.