Generic Structure

Use strict

Always start your file with

 use strict;

This makes the Perl parser stricter and protects you against typo's.

Excercise

Try out the following two code blocks. Explain the different behavior.

 # First block
 my @name;
 name[0] = 'Jason';
 nams[1] = 'Peter';
 print("First name: ", $name[0]);

 # Second block
 use strict;
 my @name;
 name[0] = 'Jason';
 nams[1] = 'Peter';
 print("First name: ", $name[0]);

Document your code: comment

Comment is denoted by the number sign #. Everything up to end of line is ignored:

 # This is comment
 # This too
 my $t;                         # This is comment too

Document your code: Plain old documentation (POD)

POD's are started with =head1, =head3 etc. at the first column and end with =cut. When you run

 perldoc myfile.pl

then the docs are shown on screen. Great way to let others know what your code is about. Your file could look as follows:

 =head1 Names

 The names of recipitents are kept in the array @names. The addresses are
 kept in a hash %address. The names are the keys into the address hash.

 =cut

 my @names;
 my %address;