Scripting Best Practices: Page 2

Posted September 4, 2008

Juliet Kemp

Juliet Kemp

(Page 2 of 3)

A perl-specific tip: the single most helpful thing you can do for yourself is to use these lines in every script:

#!/usr/bin/perl -w
use strict;
The -w flag turns on warnings. This means that if perl sees something that it thinks looks dubious (e.g. variables mentioned only once), it'll tell you so.

use strict requires you to declare all your variables before (or at least at) their first use. Thus,

my $newvar;
// some stuff
$newvar = 3;  
will be AOK, as would my $newvar = 3. But $newvar = 3 without the declaration (or a local declaration) will cause an error. This is fantastic for avoiding typos or variable name brain-blips: if you declared $newvar and then use $newcar a few lines down, you'll be warned.

Page 2 of 3

Previous Page
1 2 3
Next Page

Tags: email, job, IT, VAR

0 Comments (click to add your comment)
Comment and Contribute


(Maximum characters: 1200). You have characters left.



IT Management Daily
Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that datamation.com may send you Datamation offers via email, phone and text message, as well as email offers about other products and services that Datamation believes may be of interest to you. Datamation will process your information in accordance with the Quinstreet Privacy Policy.