Introduction to
Perl Best Practices
  José Castro <cog@cpan.org>
     Tokyo, September 2009
Who am I?
• Perl Hacker from Portugal
• COG@CPAN
• YAPC::EU::20{04,05,06,07,08,09},
  YAPC::NA::20{05,06,07,08},
  YAPC::Asia 20{08,09}, LPW 20{04,05},
  PPW 2008, OSDC::AU 2006
• Technology Evangelist @ SAPO
                          SAPO/Portugal
  Telecom
What is SAPO?
What is SAPO?
What is SAPO?
• Older than Google,
  kind of like Yahoo!
What is SAPO?
• Older than Google,
  kind of like Yahoo!
• 100+ techs
What is SAPO?
• Older than Google,
  kind of like Yahoo!
• 100+ techs
• 100+ non-techs
What is SAPO?
• Older than Google,
  kind of like Yahoo!
• 100+ techs
• 100+ non-techs
• Mail, Blogs, Photos,Videos, Links, Cars, Real
  Estate, Jobs, Maps, Encyclopedia online,
  Search, Messaging, Social Network, etc., etc.,
  etc.
What do I do at SAPO?
What do I do at SAPO?

• Evangelism (motivation, productivity, quality)
What do I do at SAPO?

• Evangelism (motivation, productivity, quality)
• Organize the training program
What do I do at SAPO?

• Evangelism (motivation, productivity, quality)
• Organize the training program
• Recruitment (lots of interviews every week)
What do I do at SAPO?

• Evangelism (motivation, productivity, quality)
• Organize the training program
• Recruitment (lots of interviews every week)
• Organize events
What do I do at SAPO?

• Evangelism (motivation, productivity, quality)
• Organize the training program
• Recruitment (lots of interviews every week)
• Organize events
• Etc.
Introduction to
Perl Best Practices
  José Castro <cog@cpan.org>
     Tokyo, September 2009
“What?”


• a set of suggestions/guidelines to improve
  your code’s readability and reliability
Disclaimer


• what works for a particular situation may
  not be adequate for another
• YMMV
“Why?”

• tomorrow, you may need to fix a glitch in
  your code
• next week, you may need to confirm
  something
• 6 months from now, you may need to
  develop a new feature
“How?”


• using standards
• defining your best practices and following
  them
Code Sample #1
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
Block separation

• A program is a list of instructions
• You’re writing it as a letter
• Separate your paragraphs, for clarity
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
use strict;

my @list=('Emacs', 'Vi      '); my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

my $i=int ($rand+rand());

print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";

}
Separate instructions


• Each instruction should have its own line
use strict;

my @list=('Emacs', 'Vi      '); my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

my $i=int ($rand+rand());

print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";

}
use strict;

my @list=('Emacs', 'Vi      ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

my $i=int ($rand+rand());

print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";

}
Indentation

• 2 spaces?
• 4 spaces?
• 6, 8?
• Tabs?
use strict;

my @list=('Emacs', 'Vi      ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

my $i=int ($rand+rand());

print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";

}
use strict;

my @list=('Emacs', 'Vi   ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

    my $i=int ($rand+rand());

    print " $list[$i] users are from Venus" . ", " .
    "$list[1-$i] users are from Mars" .
    "n";

}
Spaces around
         operators

• Don’t clutter things up
• Spaces around operators help you find
  them more easily
use strict;

my @list=('Emacs', 'Vi   ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

    my $i=int ($rand+rand());

    print " $list[$i] users are from Venus" . ", " .
    "$list[1-$i] users are from Mars" .
    "n";

}
use strict;

my @list=('Emacs', 'Vi   ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

    my $i=int ($rand+rand());

    print " $list[$i] users are from Venus" . ", " .
    "$list[1-$i] users are from Mars" .
    "n";

}
use strict;

my @list = ('Emacs', 'Vi   ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

    my $i = int ($rand + rand());

    print " $list[$i] users are from Venus" . ", " .
    "$list[1-$i] users are from Mars" .
    "n";

}
Naming variables

• Don’t name them “var”, “list”, “hash” or
  anything else that does not have a meaning
• Make sure the name helps you identify
  what it is
use strict;

my @list = ('Emacs', 'Vi   ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

    my $i = int ($rand + rand());

    print " $list[$i] users are from Venus" . ", " .
    "$list[1-$i] users are from Mars" .
    "n";

}
use strict;

my @editors = ('Emacs', 'Vi   ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

    my $i = int ($rand + rand());

    print " $editors[$i] users are from Venus" . ",
    "$editors[1-$i] users are from Mars" .
    "n";

}
Vertical indentation


• Vertical indentation helps your eyes find
  things more easily
use strict;

my @editors = ('Emacs', 'Vi   ');
my $rand = rand();

print "10 random users said:n";

foreach(0..10) {

    my $i = int ($rand + rand());

    print " $editors[$i] users are from Venus" . ",
    "$editors[1-$i] users are from Mars" .
    "n";

}
use strict;

my @editors = ('Emacs', 'Vi   ');
my $rand    = rand();

print "10 random users said:n";

foreach(0..10) {

    my $i = int ($rand + rand());

    print " $editors[$i] users are from Venus" . ",
    "$editors[1-$i] users are from Mars" .
    "n";

}
Code Sample #2
my @list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377,

for my $number (@list) {
    if (grep{$number==$_}@list2) {print "$number is
}
my @list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377,

for my $number (@list) {
    if (grep{$number==$_}@list2) {print "$number is
}
my @list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377,

for my $number (@list) {
    if (grep{$number==$_}@list2) {print "$number is
}
my @list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377,

for my $number (@list) {
    if (grep{$number==$_}@list2) {print "$number is
}
my @list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377,

for my $number (@list) {
    if (grep{$number==$_}@list2) {print "$number is
}
2 is both a prime number and a fibonacci number
3 is both a prime number and a fibonacci number
5 is both a prime number and a fibonacci number
13 is both a prime number and a fibonacci number
89 is both a prime number and a fibonacci number
Strict and warnings


• both strict and warnings will help you avoid
  lots of pesky mistakes
my @list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377,

for my $number (@list) {
    if (grep{$number==$_}@list2) {print "$number is
}
use strict;
use warnings;

my @list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377,

for my $number (@list) {
    if (grep{$number==$_}@list2) {print "$number is
}
Avoid lines over 80 charac

• code is easier to read if it fits on the screen
• even if using line wrapping, having to figure
  out if two lines are different instructions or
  the same one is harder than not having to
  do it
use strict;
use warnings;

my @list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377,

for my $number (@list) {
    if (grep{$number==$_}@list2) {print "$number is
}
use strict;
use warnings;

my @list = (2,3,5,7,11,13,17,19,23,29,31,
37,41,43,47,53,59,61,67,71,73,79,83,89,97,101) ;
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,
144,233,377,610,987,1597,2584,4181,6765) ;

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number and a
}
use strict;
use warnings;

my @list = (2,3,5,7,11,13,17,19,23,29,31,
37,41,43,47,53,59,61,67,71,73,79,83,89,97,101) ;
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,
144,233,377,610,987,1597,2584,4181,6765) ;

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " . " a
}
use strict;
use warnings;

my @list = (2,3,5,7,11,13,17,19,23,29,31,
37,41,43,47,53,59,61,67,71,73,79,83,89,97,101) ;
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,
144,233,377,610,987,1597,2584,4181,6765) ;

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
        " and a fibonacci numbern"}
}
When breaking lines,
   align vertically

• a broken line is a visual accident waiting to
  happen
use strict;
use warnings;

my @list = (2,3,5,7,11,13,17,19,23,29,31,
37,41,43,47,53,59,61,67,71,73,79,83,89,97,101) ;
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,
144,233,377,610,987,1597,2584,4181,6765) ;

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
        " and a fibonacci numbern"}
}
use strict;
use warnings;

my @list = (2,3,5,7,11,13,17,19,23,29,31,
            37,41,43,47,53,59,61,67,71,73,79,83,89,9
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,
             144,233,377,610,987,1597,2584,4181,6765

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
Add spaces after a
         comma

• spaces after a comma help you visually
  separate items
use strict;
use warnings;

my @list = (2,3,5,7,11,13,17,19,23,29,31,
            37,41,43,47,53,59,61,67,71,73,79,83,89,9
my @list2 = (1,1,2,3,5,8,13,21,34,55,89,
             144,233,377,610,987,1597,2584,4181,6765

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
use strict;
use warnings;

my @list = (2, 3, 5, 7, 11,   13, 17, 19, 23, 29, 31,
            37, 41, 43, 47,   53, 59, 61, 67, 71, 73,
my @list2 = (1, 1, 2, 3, 5,   8, 13, 21, 34, 55, 89,
             144, 233, 377,   610, 987, 1597, 2584, 41

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
Organize long lists
        as tables

• the brain identifies patterns such as tables
  much more easily
use strict;
use warnings;

my @list = (2, 3, 5, 7, 11,   13, 17, 19, 23, 29, 31,
            37, 41, 43, 47,   53, 59, 61, 67, 71, 73,
my @list2 = (1, 1, 2, 3, 5,   8, 13, 21, 34, 55, 89,
             144, 233, 377,   610, 987, 1597, 2584, 41

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
use strict;
use warnings;

my @list = ( 2, 3, 5, 7,      11, 13, 17, 19, 23, 29,
            37, 41, 43, 47,   53, 59, 61, 67, 71, 73,
my @list2 = (1, 1, 2, 3, 5,   8, 13, 21, 34, 55, 89,
             144, 233, 377,   610, 987, 1597, 2584, 41

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
use strict;
use warnings;

my @list = ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
            37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
my @list2 = ( 1,    1,   2,   3,   5,    8,   13, 2
             144, 233, 377, 610, 987, 1597, 2584, 41

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
Again, name variables
    appropriately

• the brain identifies patterns such as tables
  much more easily
use strict;
use warnings;

my @list = ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
            37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
my @list2 = ( 1,    1,   2,   3,   5,    8,   13, 2
             144, 233, 377, 610, 987, 1597, 2584, 41

for my $number (@list) {
    if (grep{$number==$_}@list2) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {
    if (grep{$number==$_}@fibonnaci) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
Spaces for clarity

• around operators
• around blocks
• around anything else that may cause
  confusion
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {
    if (grep{$number==$_}@fibonnaci) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {
    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
Block closing

• the closing curly brace should be in a line
  by itself
• this helps better identify where the block
  ends
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {
    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"}
}
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {
    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"
    }
}
Always end a statement
   with a semicolon
• even if it’s the last statement in the block
• even if the closing curly brace is on the
  same line
• this will allow you to add another
  statement without having to check the line
  above
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {
    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern"
    }
}
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {
    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern";
    }
}
Inside a loop, use empty
 lines around the body

• this is also going to help you identify the
  beginning and the end of the loop
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {
    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern";
    }
}
use strict;
use warnings;

my @prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19,
                     37, 41, 43, 47, 53, 59, 61, 67,
my @fibonnaci     = ( 1,    1,   2,   3,   5,    8,
                     144, 233, 377, 610, 987, 1597,

for my $number (@prime_numbers) {

    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern";
    }

}
Code Sample #3
for my $number (@prime_numbers) {

    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern";
    }

}
if ( grep { $number == $_ } @fibonnaci ) {
Using CPAN


• Many modules on CPAN already implement
  what we need in a far better way than we
  could possibly do in a couple of minutes
grep { 2 == $_ }
     (   1,   1,    2,    3,    5,    8,    13,
        21, 34,    55,   89, 144, 233,     377,
       610, 987, 1597, 2584, 4181, 6765, 10946)




  if ( grep { $number == $_ } @fibonnaci ) {
grep { 2 == $_ }
     (   1,   1,    2,    3,    5,    8,    13,
        21, 34,    55,   89, 144, 233,     377,
       610, 987, 1597, 2584, 4181, 6765, 10946)




  if ( grep { $number == $_ } @fibonnaci ) {
grep { 2 == $_ }
     (   1,   1,    2,    3,    5,    8,    13,
        21, 34,    55,   89, 144, 233,     377,
       610, 987, 1597, 2584, 4181, 6765, 10946)




  if ( grep { $number == $_ } @fibonnaci ) {
grep { 2 == $_ }
     (   1,   1,    2,    3,    5,    8,    13,
        21, 34,    55,   89, 144, 233,     377,
       610, 987, 1597, 2584, 4181, 6765, 10946)




  if ( grep { $number == $_ } @fibonnaci ) {
grep { 2 == $_ }
     (   1,   1,    2,    3,    5,    8,    13,
        21, 34,    55,   89, 144, 233,     377,
       610, 987, 1597, 2584, 4181, 6765, 10946)




  if ( grep { $number == $_ } @fibonnaci ) {
grep { 2 == $_ }
     (   1,   1,    2,    3,    5,    8,    13,
        21, 34,    55,   89, 144, 233,     377,
       610, 987, 1597, 2584, 4181, 6765, 10946)




  if ( grep { $number == $_ } @fibonnaci ) {
grep { 2 == $_ }
     (   1,   1,    2,    3,    5,    8,    13,
        21, 34,    55,   89, 144, 233,     377,
       610, 987, 1597, 2584, 4181, 6765, 10946)

                n iterations, always

  if ( grep { $number == $_ } @fibonnaci ) {
if ( grep { $number == $_ } @fibonnaci ) {
use List::MoreUtils qw(any);


if ( grep { $number == $_ } @fibonnaci ) {
use List::MoreUtils qw(any);


if ( any   { $number == $_ } @fibonnaci ) {
Structure


• separate your code in subroutines
• subroutines should have meaningful names
use List::MoreUtils qw(any);


if ( any   { $number == $_ } @fibonnaci ) {
use List::MoreUtils qw(any);


if ( is_fibonnaci($number) ) {


sub is_fibonnaci {
    my $number = shift;
    return any { $number == $_ } @fibonnaci
}
for my $number (@prime_numbers) {

    if ( grep { $number == $_ } @fibonnaci ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern";
    }

}
for my $number (@prime_numbers) {

    if ( is_fibonnaci($number) ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern";
    }

}
for my $number (@prime_numbers) {

    if ( is_fibonnaci($number) ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern";
    }

}

sub is_fibonnaci {
    my $number = shift;
    return any { $number == $_ } @fibonnaci;
for my $number (@prime_numbers) {

    if ( is_fibonnaci($number) ) {
        print "$number is both a prime number " .
              " and a fibonacci numbern";
    }

}
for (@prime_numbers) {

    if ( is_fibonnaci($_) ) {
        print "$_ is both a prime number     " .
              " and a fibonacci numbern";
    }

}
Code Sample #4
for ( 1 .. 1000000000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
for ( 1 .. 1000000000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
for ( 1 .. 1000000000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
for ( 1 .. 1000000000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
for ( 1 .. 1000000000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
for ( 1 .. 1000000000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
Underscores
    for large numbers

• Large numbers are hard to read
• Underscores every three digits can help
for ( 1 .. 1000000000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
for ( 1 .. 1_000_000_000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
Booleans


• flags shouldn’t be named “flag”
• they should have intuitive names
for ( 1 .. 1_000_000_000 ) {
    my $flag = 1;

    $flag = 0 if is_prime( $_ );
    $flag = 0 if is_fibonnaci( $_ );

    if ( $flag ) {
        print "$_ seems interestingn";
    }
}
for ( 1 .. 1_000_000_000 ) {
    my $is_interesting = 1;

    $is_interesting = 0 if is_prime( $_ );
    $is_interesting = 0 if is_fibonnaci( $_ );

    if ( $is_interesting ) {
        print "$_ seems interestingn";
    }
}
Tools and helpers
Perl Best Practices
                                                                                @M"   I.'(9)*'$.&8$'.(,8(/=+$8C'(,-'($'%*%?/5/,4(8<(58)>()9=?'$."
                                                                                DO"   X%4(89,(=95,/5/)'(.,$/)>.(8C'$(=95,/+5'(5/)'."
                                                                                                                                                                Documentation
                                                                                D!"   I.'(%(-'$'*8&(;-')(%(=95,/5/)'(.,$/)>('G&''*.(,;8(5/)'."                  LF"    A/.,/)>9/.-(9.'$(*8&9='),%,/8)(<$8=(,'&-)/&%5(*8&9='),%,/8)"
                                                                                D6"   I.'(%(E,-'$'*8&B(;-')(%(-'$'*8&(;895*(&8=+$8=/.'(489$(/)*'),%N            LH"    S$'%,'(.,%)*%$*(K_A(,'=+5%,'.(<8$(=8*95'.(%)*(%++5/&%,/8)."
Reference Guide                                                                 D@"
                                                                                      ,/8)"
                                                                                      W%:'('C'$4(-'$'*8&(,'$=/)%,8$(%(./)>5'(9++'$&%.'(/*'),/</'$(;/,-(%(
                                                                                                                                                                LJ"
                                                                                                                                                                LL"
                                                                                                                                                                       VG,')*(%)*(&9.,8=/0'(489$(.,%)*%$*(K_A(,'=+5%,'."
                                                                                                                                                                       K9,(9.'$(*8&9='),%,/8)(/)(.89$&'(</5'."
                                                                                      .,%)*%$*(+$'</G"                                                          LM"    1''+(%55(9.'$(*8&9='),%,/8)(/)(%(./)>5'(+5%&'(;/,-/)(489$(.89$&'(
                                                                                DD"   Y-')(/),$8*9&/)>(%(-'$'*8&Q(Z98,'(,-'(,'$=/)%,8$"                                </5'"
Code Layout                                                                     DF"   A8)B,(9.'(?%$';8$*."                                                      MO"    K5%&'(K_A(%.(&58.'(%.(+8../?5'(,8(,-'(')*(8<(,-'(</5'"
                                                                                DH"   3'.'$C'(#$(<8$(+%/$."                                                     M!"    79?*/C/*'(489$(,'&-)/&%5(*8&9='),%,/8)(%++$8+$/%,'54"
!"    #$%&'(%)*(+%$'),-'./0'(/)(123(.,45'"
                                                                                DJ"   A8)B,(9.'(&8==%.(,8(.'Z9')&'(.,%,'='),."                                  M6"    I.'(?58&:(,'=+5%,'.(<8$(=%^8$(&8=='),."
6"    7'+%$%,'(489$(&8),$85(:'4;8$*.(<$8=(,-'(<8558;/)>(8+')/)>(
                                                                                DL"   A8)B,(=/G(-/>-N(%)*(58;N+$'&'*')&'(?885'%)."                              M@"    I.'(<955N5/)'(&8=='),.(,8('G+5%/)(,-'(%5>8$/,-="
      ?$%&:',"
                                                                                DM"   K%$'),-'./0'('C'$4($%;(5/.,"                                              MD"    I.'(')*N8<N5/)'(&8=='),.(,8(+8/),(89,(.9?,5',/'.(%)*(8**/,/'."
@"    A8)B,(.'+%$%,'(.9?$89,/)'(8$(C%$/%?5'()%='.(<$8=(,-'(<8558;/)>(
                                                                                FO"   I.'(,%?5'N588:9+(,8(,'.,(<8$(='=?'$.-/+(/)(5/.,.(8<(.,$/)>.[(9.'(+),%&'   MF"    S8=='),(%)4,-/)>(,-%,(-%.(+9005'*(8$(,$/&:'*(489"
      8+')/)>(?$%&:',"
                                                                                      <8$(='=?'$.-/+(8<(5/.,.(8<(%)4,-/)>('5.'"                                 MH"    S8)./*'$(;-',-'$(/,B.(?',,'$(,8($';$/,'(,-%)(,8(&8=='),"
D"    A8)B,(9.'(9))'&'..%$4(+%$'),-'.'.(<8$(?9/5,/).(%)*(E-8)8$%$4B(
                                                                                                                                                                MJ"    I.'(E/)C/./?5'B(K_A(.'&,/8).(<8$(58)>'$(,'&-)/&%5(*/.&9../8)."
      ?9/5,/)."
F"    7'+%$%,'(&8=+5'G(:'4.(8$(/)*/&'.(<$8=(,-'/$(.9$$89)*/)>(?$%&:',."         Variables                                                                       ML"    S-'&:(,-'(.+'55/)>Q(.4),%GQ(%)*(.%)/,4(8<(489$(*8&9='),%,/8)"
H"    I.'(;-/,'.+%&'(,8(-'5+(?/)%$4(8+'$%,8$.(.,%)*(89,(<$8=(,-'/$(             F!"   TC8/*(9./)>()8)N5'G/&%5(C%$/%?5'."
      8+'$%)*."                                                                 F6"   A8)B,(9.'(+%&:%>'(C%$/%?5'.(/)(489$(8;)(*'C'58+='),"
                                                                                                                                                                Built-in Functions
J"    K5%&'(%(.'=/&858)(%<,'$('C'$4(.,%,'='),"                                  F@"   P<(489B$'(<8$&'*(,8(=8*/<4(%(+%&:%>'(C%$/%?5'Q("('+"/0'(/,"               MM"    A8)B,($'&8=+9,'(.8$,(:'4.(/)./*'(%(#(%*"
L"    K5%&'(%(&8==%(%<,'$('C'$4(C%59'(/)(%(=95,/5/)'(5/.,"                                                                                                      !OO"   I.'(%!8!%#!(,8($'C'$.'(%(5/.,"
                                                                                FD"   P)/,/%5/0'(%)4(C%$/%?5'(489("('+"/0'"
M"    I.'(JLN&859=)(5/)'."
                                                                                FF"   -#!./)0"1#2(<8$(,-'(5'..(<%=/5/%$(+9)&,9%,/8)(C%$/%?5'."                  !O!"   I.'(.&%5%$(%!8!%#!(,8($'C'$.'(%(.&%5%$"
!O"   I.'(<89$N&859=)(/)*'),%,/8)(5'C'5."
                                                                                FH"   P<(489B$'(<8$&'*(,8(=8*/<4(%(+9)&,9%,/8)(C%$/%?5'Q("('+"/0'(/,"           !O6"   I.'(-)5+'9 (,8('G,$%&,(</G'*N;/*,-(</'5*."
!!"   P)*'),(;/,-(.+%&'.Q()8,(,%?."
!6"   R'C'$(+5%&'(,;8(.,%,'='),.(8)(,-'(.%='(5/)'"                              FJ"   A8)B,(9.'(,-'($'>'G(=%,&-(C%$/%?5'."                                      !O@"   I.'(#5"1*(,8('G,$%&,(./=+5'(C%$/%?5'N;/*,-(</'5*."
!@"   S8*'(/)(+%$%>$%+-."                                                       FL"   #';%$'(8<(%)4(=8*/</&%,/8)(C/%(()"                                        !OD"   I.'(*+,-../01)20(,8('G,$%&,(&8=+5'G(C%$/%?5'N;/*,-(</'5*."
!D"   A8)B,(&9**5'(%)(!"#!"
                                                                                FM"   I.'()'>%,/C'(/)*/&'.(;-')(&89),/)>(<$8=(,-'(')*(8<(%)(%$$%4"              !OF"   TC8/*(.,$/)>(!8+""
                                                                                HO"   %:'(%*C%),%>'(8<(-%.-(%)*(%$$%4(.5/&/)>"                                 !OH"   S8)./*'$(?9/5*/)>(489$(.8$,/)>($89,/)'.(;/,-(034-..567+4"
!F"   T5/>)(&8$$'.+8)*/)>(/,'=.(C'$,/&%554"
                                                                                H!"   I.'(%(,%?95%$(5%489,(<8$(.5/&'."                                          !OJ"   I.'(DN%$>(#-:#*%(/).,'%*(8<(5C%59'(#-:#*%"
!H"   #$'%:(58)>('G+$'../8).(?'<8$'(%)(8+'$%,8$"
                                                                                H6"   U%&,8$(5%$>'(:'4(8$(/)*'G(5/.,.(89,(8<(,-'/$(.5/&'."                      !OL"   W%:'(%++$8+$/%,'(9.'(8<(5C%59'(C%59'."
!J"   U%&,8$(89,(58)>('G+$'../8).(/)(,-'(=/**5'(8<(.,%,'='),."
!L"   T5;%4.(?$'%:(%(58)>('G+$'../8)(%,(,-'(8+'$%,8$(8<(,-'(58;'.,(+8../N                                                                                       !OM"   I.'(0"(:Q()8,(8]$"
      ?5'(+$'&'*')&'"                                                           Control Structures                                                              !!O"   TC8/*(%($%;(#!"!'*(<8$()8)N/),'>'$(.5''+."
!M"   #$'%:(58)>(%../>)='),.(?'<8$'(,-'(%../>)='),(8+'$%,8$"                                                                                                    !!!"   T5;%4.(9.'(%(?58&:(;/,-(%(4+5(%)*(0%!5"
                                                                                H@"   I.'(?58&:(1&Q()8,(+8.,</G(1&"                                             !!6"   I.'(,-'(E)8)N?9/5,/)(?9/5,/).B"
6O"   U8$=%,(&%.&%*'*(,'$)%$4(8+'$%,8$.(/)(&859=)."                             HD"   3'.'$C'(+8.,</G(1&(<8$(<58;N8<N&8),$85(.,%,'='),."
6!"   K%$'),-'./0'(58)>(5/.,."
                                                                                HF"   A8)B,(9.'(+8.,</G(-)"!##Q(&(%Q(321"!Q(8$(-)*1""
66"   V)<8$&'(489$(&-8.')(5%489,(.,45'(='&-%)/&%554"
                                                                                HH"   A8)B,(9.'(-)"!##(8$(-)*1"(%,(%55"                                         Subroutines
                                                                                HJ"   TC8/*(SN.,45'(&(%(.,%,'='),."                                             !!@"   S%55(.9?$89,/)'.(;/,-(+%$'),-'.'.(?9,(;/,-89,(%(5'%*/)>(9"
Naming Conventions                                                              HL"   TC8/*(.9?.&$/+,/)>(%$$%4.(8$(-%.-'.(;/,-/)(588+."                         !!D"   A8)B,(>/C'(.9?$89,/)'.(,-'(.%='()%='.(%.(?9/5,N/)(<9)&,/8)."
6@"   I.'(>$%==%,/&%5(,'=+5%,'.(;-')(<8$=/)>(/*'),/</'$."                       HM"   R'C'$(.9?.&$/+,(=8$'(,-%)(8)&'(/)(%(588+"                                 !!F"   T5;%4.(9)+%&:(:)(</$.,"
6D"   R%='(?885'%).(%<,'$(,-'/$(%..8&/%,'*(,'.,"                                JO"   I.'()%='*(5'G/&%5.(%.('G+5/&/,(&(%(588+(/,'$%,8$."                        !!H"   I.'(%(-%.-(8<()%='*(%$>9='),.(<8$(%)4(.9?$89,/)'(,-%,(-%.(=8$'(
6F"   W%$:(C%$/%?5'.(,-%,(.,8$'($'<'$')&'.(;/,-(%($%!&(.9<</G"                  J!"   T5;%4.(*'&5%$'(%(&(%(588+(/,'$%,8$(C%$/%?5'(;/,-(4,"                             ,-%)(,-$''(+%$%=','$."
6H"   R%='(%$$%4.(/)(,-'(+59$%5(%)*(-%.-'.(/)(,-'(./)>95%$"                     J6"   I.'(4+5(/).,'%*(8<(&(%(;-')(>')'$%,/)>()';(5/.,.(<$8=(85*"                !!J"   I.'(6!&1)!6)'..(8$(!71#*')&'(,8(,'.,(<8$(=/../)>(%$>9='),."
6J"   I.'(9)*'$.&8$'.(,8(.'+%$%,'(;8$*.(/)(=95,/;8$*(/*'),/</'$."               J@"   I.'(0%!5(%)*(&1%#*(/).,'%*(8<(&(%(;-')(.'%$&-/)>(<8$(C%59'.(/)(%(5/.,"    !!L"   3'.85C'(%)4(*'<%95,(%$>9='),(C%59'.(%.(.88)(%.(:)(/.(9)+%&:'*"
6L"   A/.,/)>9/.-(*/<<'$'),(+$8>$%=(&8=+8)'),.(?4(&%.'"                         JD"   I.'(&(%(/).,'%*(8<(4+5(;-')(,$%).<8$=/)>(%(5/.,(/)(+5%&'"                 !!M"   T5;%4.($',9$)(.&%5%$(/)(.&%5%$($',9$)."
6M"   T??$(/*'),.(?4(+$'<G"                                                     JF"   I.'(%(.9?$89,/)'(&%55(,8(<%&,8$(89,(&8=+5'G(5/.,(,$%).<8$=%,/8)."         !6O"   W%:'(5/.,N$',9$)/)>(.9?$89,/)'.($',9$)(,-'(E8?C/89.B(C%59'(/)(.&%5%$(
@O"   T??$'C/%,'(8)54(;-')(,-'(='%)/)>($'=%/).(9)%=?/>989."                     JH"   R'C'$(=8*/<4(()(/)(%(5/.,(<9)&,/8)"                                              &8),'G,"
@!"   TC8/*(9./)>(/)-'$'),54(%=?/>989.(;8$*.(/)()%='."                          JJ"   TC8/*(&%.&%*/)>(%)(1&"                                                    !6!"   Y-')(,-'$'(/.()8(E8?C/89.B(.&%5%$(&8),'G,($',9$)(C%59'Q(&8)./*'$(
@6"   K$'</G(E<8$(/),'$)%5(9.'(8)54B(.9?$89,/)'.(;/,-(%)(9)*'$.&8$'"            JL"   I.'(,%?5'(588:N9+(/)(+$'<'$')&'(,8(&%.&%*'*('Z9%5/,4(,'.,."                      /3;-+,-<6=..>+-<4;(/).,'%*"
                                                                                JM"   Y-')(+$8*9&/)>(%(C%59'Q(9.'(,%?95%$(,'$)%$/'."                            !66"   A8)B,(9.'(.9?$89,/)'(+$8,8,4+'."
                                                                                                                                                                       T5;%4.($',9$)(C/%(%)('G+5/&/,(%!*-%)"
Values and Expressions                                                          LO"   A8)B,(9.'(6(]321"!(588+."                                                 !6@"
                                                                                                                                                                !6D"   I.'(%(?%$'(%!*-%)(,8($',9$)(<%/59$'"
                                                                                L!"   3'^'&,(%.(=%)4(/,'$%,/8).(%.(+8../?5'Q(%.('%$54(%.(+8../?5'"
@@" I.'(/),'$+85%,/)>(.,$/)>(*'5/=/,'$.(8)54(<8$(.,$/)>.(,-%,(%&,9%554(/),'$N   L6"   A8)B,(&8),8$,(588+(.,$9&,9$'.(^9.,(,8(&8).85/*%,'(&8),$85"
    +85%,'"
@D" A8)B,(9.'(!!(8$(""(<8$(%)('=+,4(.,$/)>"
                                                                                L@"   I.'(&(%(%)*(%!6((/).,'%*(8<(%)(/$$'>95%$54(&89),'*(321"!"                 I/O
                                                                                LD"   X%?'5('C'$4(588+(,-%,(/.('G/,'*('G+5/&/,54Q(%)*(9.'(,-'(5%?'5(;/,-(
@F" A8)B,(;$/,'(8)'N&-%$%&,'$(.,$/)>.(/)(C/.9%554(%=?/>989.(;%4."                                                                                               !6F" A8)B,(9.'(?%$';8$*(</5'-%)*5'."
                                                                                      'C'$4()!7*Q("+#*Q(8$(%!6("                                                !6H" I.'(/)*/$'&,(</5'-%)*5'."
@H" I.'()%='*(&-%$%&,'$('.&%+'.(/).,'%*(8<()9='$/&('.&%+'."
@J" I.'()%='*(&8).,%),.Q(?9,(*8)B,(9.'('()#*+)*"                                                                                                                !6J" P<(489(-%C'(,8(9.'(%(+%&:%>'(</5'-%)*5'Q("('+"/0'(/,(</$.,"
@L" A8)B,(+%*(*'&/=%5()9=?'$.(;/,-(5'%*/)>(0'$8."
Perl Best Practices
                                                                              @M"   I.'(9)*'$.&8$'.(,8(/=+$8C'(,-'($'%*%?/5/,4(8<(58)>()9=?'$."
                                                                              DO"   X%4(89,(=95,/5/)'(.,$/)>.(8C'$(=95,/+5'(5/)'."
                                                                                                                                                              Documentation
                                                                              D!"   I.'(%(-'$'*8&(;-')(%(=95,/5/)'(.,$/)>('G&''*.(,;8(5/)'."                  LF"   A/.,/)>9/.-(9.'$(*8&9='),%,/8)(<$8=(,'&-)/&%5(*8&9='),%,/8)"
                                                                              D6"   I.'(%(E,-'$'*8&B(;-')(%(-'$'*8&(;895*(&8=+$8=/.'(489$(/)*'),%N            LH"   S$'%,'(.,%)*%$*(K_A(,'=+5%,'.(<8$(=8*95'.(%)*(%++5/&%,/8)."
Reference Guide                                                               D@"
                                                                                    ,/8)"
                                                                                    W%:'('C'$4(-'$'*8&(,'$=/)%,8$(%(./)>5'(9++'$&%.'(/*'),/</'$(;/,-(%(
                                                                                                                                                              LJ"
                                                                                                                                                              LL"
                                                                                                                                                                    VG,')*(%)*(&9.,8=/0'(489$(.,%)*%$*(K_A(,'=+5%,'."
                                                                                                                                                                    K9,(9.'$(*8&9='),%,/8)(/)(.89$&'(</5'."
                                                                                    .,%)*%$*(+$'</G"                                                          LM"   1''+(%55(9.'$(*8&9='),%,/8)(/)(%(./)>5'(+5%&'(;/,-/)(489$(.89$&'(
                                                                              DD"   Y-')(/),$8*9&/)>(%(-'$'*8&Q(Z98,'(,-'(,'$=/)%,8$"                               </5'"
Code Layout                                                                   DF"   A8)B,(9.'(?%$';8$*."                                                      MO"   K5%&'(K_A(%.(&58.'(%.(+8../?5'(,8(,-'(')*(8<(,-'(</5'"
                                                                              DH"   3'.'$C'(#$(<8$(+%/$."                                                     M!"   79?*/C/*'(489$(,'&-)/&%5(*8&9='),%,/8)(%++$8+$/%,'54"
!"   #$%&'(%)*(+%$'),-'./0'(/)(123(.,45'"
                                                                              DJ"   A8)B,(9.'(&8==%.(,8(.'Z9')&'(.,%,'='),."                                  M6"   I.'(?58&:(,'=+5%,'.(<8$(=%^8$(&8=='),."
6"   7'+%$%,'(489$(&8),$85(:'4;8$*.(<$8=(,-'(<8558;/)>(8+')/)>(
                                                                              DL"   A8)B,(=/G(-/>-N(%)*(58;N+$'&'*')&'(?885'%)."                              M@"   I.'(<955N5/)'(&8=='),.(,8('G+5%/)(,-'(%5>8$/,-="
     ?$%&:',"
                                                                              DM"   K%$'),-'./0'('C'$4($%;(5/.,"                                              MD"   I.'(')*N8<N5/)'(&8=='),.(,8(+8/),(89,(.9?,5',/'.(%)*(8**/,/'."
@"   A8)B,(.'+%$%,'(.9?$89,/)'(8$(C%$/%?5'()%='.(<$8=(,-'(<8558;/)>(
                                                                              FO"   I.'(,%?5'N588:9+(,8(,'.,(<8$(='=?'$.-/+(/)(5/.,.(8<(.,$/)>.[(9.'(+),%&'   MF"   S8=='),(%)4,-/)>(,-%,(-%.(+9005'*(8$(,$/&:'*(489"
     8+')/)>(?$%&:',"
                                                                                    <8$(='=?'$.-/+(8<(5/.,.(8<(%)4,-/)>('5.'"                                 MH"   S8)./*'$(;-',-'$(/,B.(?',,'$(,8($';$/,'(,-%)(,8(&8=='),"
D"   A8)B,(9.'(9))'&'..%$4(+%$'),-'.'.(<8$(?9/5,/).(%)*(E-8)8$%$4B(
                                                                                                                                                              MJ"   I.'(E/)C/./?5'B(K_A(.'&,/8).(<8$(58)>'$(,'&-)/&%5(*/.&9../8)."
     ?9/5,/)."
F"   7'+%$%,'(&8=+5'G(:'4.(8$(/)*/&'.(<$8=(,-'/$(.9$$89)*/)>(?$%&:',."        Variables                                                                       ML"   S-'&:(,-'(.+'55/)>Q(.4),%GQ(%)*(.%)/,4(8<(489$(*8&9='),%,/8)"
H"   I.'(;-/,'.+%&'(,8(-'5+(?/)%$4(8+'$%,8$.(.,%)*(89,(<$8=(,-'/$(               F!" TC8/*(9./)>()8)N5'G/&%5(C%$/%?5'."
     8+'$%)*."                                                                   F6" A8)B,(9.'(+%&:%>'(C%$/%?5'.(/)(489$(8;)(*'C'58+='),"
                                                                                                                                                                Built-in Functions
J"   K5%&'(%(.'=/&858)(%<,'$('C'$4(.,%,'='),"                                    F@" P<(489B$'(<8$&'*(,8(=8*/<4(%(+%&:%>'(C%$/%?5'Q("('+"/0'(/,"                MM" A8)B,($'&8=+9,'(.8$,(:'4.(/)./*'(%(#(%*"
L"   K5%&'(%(&8==%(%<,'$('C'$4(C%59'(/)(%(=95,/5/)'(5/.,"                                                                                                       !OO" I.'(%!8!%#!(,8($'C'$.'(%(5/.,"
                                                                                 FD" P)/,/%5/0'(%)4(C%$/%?5'(489("('+"/0'"
M"   I.'(JLN&859=)(5/)'."
                                                                                 FF" -#!./)0"1#2(<8$(,-'(5'..(<%=/5/%$(+9)&,9%,/8)(C%$/%?5'."                   !O!" I.'(.&%5%$(%!8!%#!(,8($'C'$.'(%(.&%5%$"
!O"  I.'(<89$N&859=)(/)*'),%,/8)(5'C'5."                            !"#$      %&'(')*+',(*+'(!"##$%&'(-./01'(.,(*+'(*+,''23,40-'5*(6.,-(.6(/0'(/," !N"$ X3='(63)1'/(D0)1*)5&(*+,.;('A<'B*).5&(*..$                                    "!K$ Y39'(3**,)D0*'&()5)*)31)V'/(35/(9',)6)'/(30*.-3*)<311C$
                                                                                 FH" P<(489B$'(<8$&'*(,8(=8*/<4(%(+9)&,9%,/8)(C%$/%?5'Q("('+"                   !O6" I.'(-)5+'9 (,8('G,$%&,(</G'*N;/*,-(</'5*."
!!"  P)*'),(;/,-(.+%&'.Q()8,(,%?."                                            !"#$$ A8)B,(9.'(,-'($'>'G(=%,&-(C%$/%?5'."                                !N>$ X3='(63)10,'&(63*31()5(311(<.5*'A*&$                                     "!M$ IB'<)6C(<.',<).5&(3&(#/3C!5J!$K:(#5LMNC!$K:(35/(#O""P!$K(-'*+./&$
!6"  R'C'$(+5%&'(,;8(.,%,'='),.(8)(,-'(.%='(5/)'"                                FJ"                                                                            !O@" I.'(#5"1*(,8('G,$%&,(./=+5'(C%$/%?5'N;/*,-(</'5*."
                                                                    !"7$      8'9',(!"#$:(%&!'#:(.,("()$*(*.(3(6)1'(;)*+.0*(<+'<=)54(*+'(.0*<.-'$ !NJ$ T'(<3,'601(;+'5(*'&*)54(6.,(63)10,'(.6(*+'('2'*#3(D0)1*)5$
                                                                                 FL" #';%$'(8<(%)4(=8*/</&%,/8)(C/%(()"                                         !OD" I.'(*+,-../01)20(,8('G,$%&,(&8=+5'G(C%$/%?5'N;/*,-(</'5*."       "!N$ %&'(#;LMLP@3!QN(-'*+./&()5&*'3/(.6(/L,NC##(<311&$
!@"  S8*'(/)(+%$%>$%+-."                                                                                                                                                                                                              "!#$ O.5P*(0&'(@L3"P"@4(+$
                                                                    !>?$         FM" I.'()'>%,/C'(/)*/&'.(;-')(&89),/)>(<$8=(,-'(')*(8<(%)(%$$%4" !NK$ U+,.;('A<'B*).5&(.5(311(63)10,'&:()5<10/)54(,'<.9',3D1'(.5'&$
                                                                              @1.&'(6)1'+35/1'&('AB1)<)*1C:(35/(3&(&..5(3&(B.&&)D1'$                            !OF" TC8/*(.,$/)>(!8+""
!D"  A8)B,(&9**5'(%)(!"#!"                                          !>!$      %&'(+,)&#(()*+:(5.*(-!((()*+$                                             !NM$ Y39'('A<'B*).5&(,'B.,*(6,.-(*+'(<311',Z&(1.<3*).5:(5.*(6,.-(*+'(B13<'(
                                                                                 HO" %:'(%*C%),%>'(8<(-%.-(%)*(%$$%4(.5/&/)>"                                  !OH" S8)./*'$(?9/5*/)>(489$(.8$,/)>($89,/)'.(;/,-(034-..567+4"
!F"  T5/>)(&8$$'.+8)*/)>(/,'=.(C'$,/&%554"
!H"  #$'%:(58)>('G+$'../8).(?'<8$'(%)(8+'$%,8$"
                                                                    !>"$      E,'6',(1)5'2D3&'/(FGH(*.(&10,B)54$
                                                                                 H!" I.'(%(,%?95%$(5%489,(<8$(.5/&'."                                        ;+','(*+'C(;','(*+,.;5$
                                                                                                                                                                !OJ" I.'(DN%$>(#-:#*%(/).,'%*(8<(5C%59'(#-:#*%"                       Modules
                                                                    !>>$      I10,B(3(6)1'+35/1'(;)*+(3(.!(D1.<=(6.,(B0,)*C$
                                                                                 H6" U%&,8$(5%$>'(:'4(8$(/)*'G(5/.,.(89,(8<(,-'/$(.5/&'."               !NN$ @.-B.&'(',,.,(-'&&34'&()5(*+'(,'<)B)'5*P&(/)31'<*$
                                                                                                                                                                !OL" W%:'(%++$8+$/%,'(9.'(8<(5C%59'(C%59'."
!J"  U%&,8$(89,(58)>('G+$'../8).(/)(,-'(=/**5'(8<(.,%,'='),."                                                                                           !N#$ O.<0-'5*('9',C(',,.,(-'&&34'()5(*+'(,'<)B)'5*P&(/)31'<*$                 "!7$ O'&)45(*+'(-./01'P&()5*',63<'(6),&*$
                                                                    !>J$      I10,B(3(&*,'3-(;)*+(,'-&.##/&0-1(6.,(B.;',(35/(&)-B1)<)*C$                        !OM" I.'(0"(:Q()8,(8]$"
!L"  T5;%4.(?$'%:(%(58)>('G+$'../8)(%,(,-'(8+'$%,8$(8<(,-'(58;'.,(+8../N                                                                                !N7$ %&'('A<'B*).5(.D['<*&(;+'5'9',(63)10,'(/3*3(5''/&(*.(D'(<.59'C'/(        ""?$ E13<'(.,)4)531(<./'()51)5'$(E13<'(/0B1)<3*'/(<./'()5(3(&0D,.0*)5'$(
                                                                    !>K$      L9.)/(0&)54((2/34!5:(051'&&(C.0(,'311C(-'35()*$
     ?5'(+$'&'*')&'"                                                !>M$
                                                                                 Control Structures
                                                                              L1;3C&(B0*(6)1'+35/1'&()5(D,3<'&(;)*+)5(35C(1-%67(&*3*'-'5*$
                                                                                                                                                                !!O" TC8/*(%($%;(#!"!'*(<8$()8)N/),'>'$(.5''+."
                                                                                                                                                             *.(3(+35/1',$                                                                 E13<'(/0B1)<3*'/(&0D,.0*)5'&()5(3(-./01'$
!M"  #$'%:(58)>(%../>)='),.(?'<8$'(,-'(%../>)='),(8+'$%,8$"                                                                                                     !!!" T5;%4.(9.'(%(?58&:(;/,-(%(4+5(%)*(0%!5"
                                                                                                                                                        !#?$ %&'('A<'B*).5(.D['<*&(;+'5(',,.,(-'&&34'&(-3C(<+354'$                    ""!$ %&'(*+,''2B3,*(9',&).5(50-D',&$
                                                                    !>N$         H@" I.'(?58&:(1&Q()8,(+8.,</G(1&"
                                                                              L1;3C&(B,.-B*(6.,()5*',3<*)9'()5B0*$                                              !!6" I.'(,-'(E)8)N?9/5,/)(?9/5,/).B"
6O"  U8$=%,(&%.&%*'*(,'$)%$4(8+'$%,8$.(/)(&859=)."                                                                                                      !#!$ %&'('A<'B*).5(.D['<*&(;+'5(*;.(.,(-.,'('A<'B*).5&(3,'(,'13*'/$           """$ 56.,<'(C.0,(9',&).5(,'^0),'-'5*&(B,.4,3--3*)<311C$
                                                                    !>#$      O.5P*(,')59'5*(*+'(&*35/3,/(*'&*(6.,()5*',3<*)9)*C$
                                                                                 HD" 3'.'$C'(+8.,</G(1&(<8$(<58;N8<N&8),$85(.,%,'='),."
6!"  K%$'),-'./0'(58)>(5/.,."                                                                                                                           !#"$ @3*<+('A<'B*).5(.D['<*&()5(-.&*2/',)9'/26),&*(.,/',$                     "">$ AB.,*([0/)<).0&1C(35/:(;+','(B.&&)D1':(.51C(DC(,'^0'&*$
                                                                    !>7$      %&'(*+'(A8)B,(9.'(+8.,</G(-)"!##Q(&(%Q(321"!Q(8$(-)*1""
                                                                                 HF" !"##,-8917(-./01'(6.,(B,.-B*)54$
66"  V)<8$&'(489$(&-8.')(5%489,(.,45'(='&-%)/&%554"                 !J?$      L1;3C&(<.59'C(*+'(B,.4,'&&(.6(1.54(5.52)5*',3<*)9'(.B',3*).5&(
                                                                                 HH" A8)B,(9.'(-)"!##(8$(-)*1"(%,(%55"                                          Subroutines
                                                                                                                                                        !#>$ T0)1/('A<'B*).5(<13&&'&(30*.-3*)<311C$                                   ""J$ @.5&)/',('AB.,*)54(/'<13,3*)9'1C$
                                                                                                                                                        !#J$ %5B3<=(*+'('A<'B*).5(93,)3D1'()5('A*'5/'/('A<'B*).5(+35/1',&$ 9"         ""K$ 8'9',(-3='(93,)3D1'&(B3,*(.6(3(-./01'P&()5*',63<'$
                                                                              ;)*+)5()5*',3<*)9'(3BB1)<3*).5&$
                                                                                 HJ" TC8/*(SN.,45'(&(%(.,%,'='),."                                              !!@" S%55(.9?$89,/)'.(;/,-(+%$'),-'.'.(?9,(;/,-89,(%(5'%*/)>(
Naming Conventions                                                      !J!$ @.5&)/',(0&)54(*+'(/9:-7##;899'67<(-./01'(*.(30*.-3*'(C.0,(
                                                                                 HL" TC8/*(.9?.&$/+,/)>(%$$%4.(8$(-%.-'.(;/,-/)(588+."
                                                                                                                                                                                                                                      ""M$ T0)1/(5';(-./01'(6,3-';.,=&(30*.-3*)<311C$
                                                                                                                                                                !!D" A8)B,(>/C'(.9?$89,/)'.(,-'(.%='()%='.(%.(?9/5,N/)(<9)&,/8)." ""N$ %&'(<.,'(-./01'&(;+','9',(B.&&)D1'$
6@" I.'(>$%==%,/&%5(,'=+5%,'.(;-')(<8$=/)>(/*'),/</'$."                       B,.4,'&&()5/)<3*.,&$
                                                                                 HM" R'C'$(.9?.&$/+,(=8$'(,-%)(8)&'(/)(%(588+"                          Command-Line Processing
                                                                                                                                                                !!F" T5;%4.(9)+%&:(:)(</$.,"                                          ""#$ %&'(@EL8(-./01'&(;+','(6'3&)D1'$
6D" R%='(?885'%).(%<,'$(,-'/$(%..8&/%,'*(,'.,"                          !J"$ L9.)/(3(,3;('#&#%*(;+'5(&'**)54(30*.610&+'&$
                                                                                 JO" I.'()%='*(5'G/&%5.(%.('G+5/&/,(&(%(588+(/,'$%,8$."                         !!H" I.'(%(-%.-(8<()%='*(%$>9='),.(<8$(%)4(.9?$89,/)'(,-%,(-%.(=8$'(
                                                                                                                                                        !#K$ 56.,<'(3(&)541'(<.5&)&*'5*(<.--35/21)5'(&*,0<*0,'$
6F" W%$:(C%$/%?5'.(,-%,(.,8$'($'<'$')&'.(;/,-(%($%!&(.9<</G"                     J!" T5;%4.(*'&5%$'(%(&(%(588+(/,'$%,8$(C%$/%?5'(;/,-(4,"                            ,-%)(,-$''(+%$%=','$."
                                                                                                                                                                !!J" I.'(6!&1)!6)'..(8$(!71#*')&'(,8(,'.,(<8$(=/../)>(%$>9='),." Testing and Debugging
                                                                                                                                                        !#M$ L/+','(*.(3(&*35/3,/(&'*(.6(<.59'5*).5&()5(C.0,(<.--35/21)5'(&C52
6H" R%='(%$$%4.(/)(,-'(+59$%5(%)*(-%.-'.(/)(,-'(./)>95%$"               References (/).,'%*(8<(&(%(;-')(>')'$%,/)>()';(5/.,.(<$8=(85*"
                                                                                 J6" I.'(4+5                                                                 *3A$
6J" I.'(9)*'$.&8$'.(,8(.'+%$%,'(;8$*.(/)(=95,/;8$*(/*'),/</'$."                                                                                         !#N$    !!L" 3'.85C'(%)4(*'<%95,(%$>9='),(C%59'.(%.(.88)(%.(:)(/.(9)+%&:'*"""7$ Q,)*'(*+'(*'&*(<3&'&(6),&*$
                                                                                 J@" I.'(0%!5(%)*(&1%#*(/).,'%*(8<(&(%(;-')(.'%$&-/)>(<8$(C%59'.(/)(%(5/.," I*35/3,/)V'(C.0,(-'*32.B*).5&$
                                                                        !J>$ Q+','9',(B.&&)D1':(/','6','5<'(;)*+(3,,.;&$                                        !!M" T5;%4.($',9$)(.&%5%$(/)(.&%5%$($',9$)."
6L" A/.,/)>9/.-(*/<<'$'),(+$8>$%=(&8=+8)'),.(?4(&%.'"                            JD" I.'(&(%(/).,'%*(8<(4+5(;-')(,$%).<8$=/)>(%(5/.,(/)(+5%&'"          !##$ L11.;(*+'(&3-'(6)1'53-'(*.(D'(&B'<)6)'/(6.,(D.*+()5B0*(35/(.0*B0*$       ">?$ I*35/3,/)V'(C.0,(*'&*&(;)*+(3'<7##/%91&'(.,(3'<7##M8-'$
                                                                        !JJ$ Q+','(B,'6)A(/','6','5<)54()&(0539.)/3D1':(B0*(D,3<'&(3,.05/(*+'(                  !6O" W%:'(5/.,N$',9$)/)>(.9?$89,/)'.($',9$)(,-'(E8?C/89.B(C%59'(/)(.&%5%$( I*35/3,/)V'(C.0,(*'&*(&0)*'&(;)*+(3'<7##R:-6'<<$
6M" T??$(/*'),.(?4(+$'<G"                                                        JF" I.'(%(.9?$89,/)'(&%55(,8(<%&,8$(89,(&8=+5'G(5/.,(,$%).<8$=%,/8)." !#7$ I*35/3,/)V'(.5(3(&)541'(3BB,.3<+(*.(<.--35/21)5'(B,.<'&&)54$              ">!$
                                                                              ,'6','5<'$                                                                             &8),'G,"
@O" T??$'C/%,'(8)54(;-')(,-'(='%)/)>($'=%/).(9)%=?/>989."                        JH" R'C'$(=8*/<4(()(/)(%(5/.,(<9)&,/8)"                                !7?$ 5&0,'(*+3*(C.0,()5*',63<':(,052*)-'(-'&&34'&:(35/(/.<0-'5*3*).5(        ">"$ Q,)*'(*'&*(<3&'&(*+3*(63)1$
                                                                        !JK$ 8'9',(0&'(&C-D.1)<(,'6','5<'&$                                                     !6!" Y-')(,-'$'(/.()8(E8?C/89.B(.&%5%$(&8),'G,($',9$)(C%59'Q(&8)./*'$(
@!" TC8/*(9./)>(/)-'$'),54(%=?/>989.(;8$*.(/)()%='."                             JJ" TC8/*(&%.&%*/)>(%)(1&"                                                  ,'-3)5(<.5&)&*'5*$                                                       ">>$ U'&*(D.*+(*+'(1)='1C(35/(*+'(051)='1C$
                                                                        !JM$ %&'(+#/0#$(*.(B,'9'5*(<),<013,(/3*3(&*,0<*0,'&(6,.-(1'3=)54(-'-.,C$                     /3;-+,-<6=..>+-<4;(/).,'%*"
@6" K$'</G(E<8$(/),'$)%5(9.'(8)54B(.9?$89,/)'.(;/,-(%)(9)*'$.&8$'"               JL" I.'(,%?5'(588:N9+(/)(+$'<'$')&'(,8(&%.&%*'*('Z9%5/,4(,'.,."        !7!$ W3<*.,(.0*(<.--.5(<.--35/21)5'()5*',63<'(<.-B.5'5*&()5*.(3(              ">J$ L//(5';(*'&*(<3&'&(D'6.,'(C.0(&*3,*(/'D044)54$
                                                                                 JM" Y-')(+$8*9&/)>(%(C%59'Q(9.'(,%?95%$(,'$)%$/'."                             !66" A8)B,(9.'(.9?$89,/)'(+$8,8,4+'."
                                                                                                                                                             &+3,'/(-./01'$                                                           ">K$ L1;3C&(4'#5'*()%*$
Values and Expressions                                                  RegularA8)B,(9.'(6(]321"!(588+."
                                                                                 LO" Expressions                                                                !6@" T5;%4.($',9$)(C/%(%)('G+5/&/,(%!*-%)"                            ">M$ L1;3C&(*0,5(.5(;3,5)54&('AB1)<)*1C$
                                                                                                                                                                !6D" I.'(%(?%$'(%!*-%)(,8($',9$)(<%/59$'"                             ">N$ 8'9',(3&&0-'(*+3*(3(;3,5)5426,''(<.-B)13*).5()-B1)'&(<.,,'<*5'&&$
                                                                                 L!" 3'^'&,(%.(=%)4(/,'$%,/8).(%.(+8../?5'Q(%.('%$54(%.(+8../?5'"
                                                                        !JN$ L1;3C&(0&'(*+'(=>(6134$
@@" I.'(/),'$+85%,/)>(.,$/)>(*'5/=/,'$.(8)54(<8$(.,$/)>.(,-%,(%&,9%554(/),'$N L1;3C&(0&'(*+'(=9(6134$                                                   Objects                                                                       ">#$ U0,5(.66(&*,)<*0,'&(.,(;3,5)54&('AB1)<)*1C:(&'1'<*)9'1C:(35/()5(*+'(
                                                                        !J#$     L6" A8)B,(&8),8$,(588+(.,$9&,9$'.(^9.,(,8(&8).85/*%,'(&8),$85"
    +85%,'"
@D" A8)B,(9.'(!!(8$(""(<8$(%)('=+,4(.,$/)>"
                                                                                 L@" I.'(&(%(%)*(%!6((/).,'%*(8<(%)(/$$'>95%$54(&89),'*(321"!"
                                                                        !J7$ %&'(?@(35/(?A(3&(&*,)54(D.05/3,C(35<+.,&$                                          I/O
                                                                                                                                                        !7"$ X3='(.D['<*(.,)'5*3*).5(3(<+.)<':(5.*(3(/'6301*$                              &-311'&*(B.&&)D1'(&<.B'$
                                                                                 LD" X%?'5('C'$4(588+(,-%,(/.('G/,'*('G+5/&/,54Q(%)*(9.'(,-'(5%?'5(;/,-(!7>$ @+..&'(.D['<*(.,)'5*3*).5(0&)54(3BB,.B,)3*'(<,)*',)3$
                                                                        !K?$ %&'(?A:(5.*(?B:(*.()5/)<3*'(R'5/(.6(&*,)54P$                                                                                                             ">7$ _'3,5(3*(1'3&*(3(&0D&'*(.6(*+'(B',1(/'D044',$
@F" A8)B,(;$/,'(8)'N&-%$%&,'$(.,$/)>.(/)(C/.9%554(%=?/>989.(;%4." !K!$ L1;3C&(0&'(*+'(=<(6134$                                                                  !6F" A8)B,(9.'(?%$';8$*(</5'-%)*5'."
                                                                                                                                                        !7J$ O.5P*(0&'(B&'0/.+3&+'&$                                                  "J?$ %&'(&',)31)V'/(;3,5)54&(;+'5(/'D044)54(R-350311CP$
                                                                                       'C'$4()!7*Q("+#*Q(8$(%!6("                                               !6H" I.'(/)*/$'&,(</5'-%)*5'."
@H" I.'()%='*(&-%$%&,'$('.&%+'.(/).,'%*(8<()9='$/&('.&%+'."             !K"$ @.5&)/',(-35/3*)54(*+'(C'D'>1##@078E&:D<(-./01'$                           !7K$ O.5P*(0&'(,'&*,)<*'/(+3&+'&$                                             "J!$ @.5&)/',(0&)54(R&-3,*(<.--'5*&P(;+'5(/'D044)54:(,3*+',(*+35(
@J" I.'()%='*(&8).,%),.Q(?9,(*8)B,(9.'('()#*+)*"                                                                                                                !6J" P<(489(-%C'(,8(9.'(%(+%&:%>'(</5'-%)*5'Q("('+"/0'(/,(</$.,"
                                                                                                                                                        !7M$ L1;3C&(0&'(6011C('5<3B&013*'/(.D['<*&$                                        +/($(&*3*'-'5*&$
                                                                        !K>$ %&'(9FSG()5(B,'6','5<'(*.(=S=()5(-01*)1)5'(,'4'A'&$
@L" A8)B,(+%*(*'&/=%5()9=?'$.(;/,-(5'%*/)>(0'$8."                       !KJ$ O.5P*(0&'(35C(/'1)-)*',&(.*+',(*+35(=S=(.,(9FSG$                           !7N$ ])9'('9',C(<.5&*,0<*.,(*+'(&3-'(&*35/3,/(53-'$
                                                                        !KK$ E,'6',(&)54013,(<+3,3<*',(<13&&'&(*.('&<3B'/(-'*3<+3,3<*',&$               !7#$ O.5P*(1'*(3(<.5&*,0<*.,(<1.5'(.D['<*&$
                                                                                                                                                        !77$ L1;3C&(B,.9)/'(3(/'&*,0<*.,(6.,('9',C()5&)/'2.0*(<13&&$
                                                                                                                                                                                                                                      Miscellanea
                                                                        !KM$ E,'6',(53-'/(<+3,3<*',&(*.('&<3B'/(-'*3<+3,3<*',&$
                                                                                                                                                        "??$ Q+'5(<,'3*)54(-'*+./&:(6.11.;(*+'(4'5',31(40)/'1)5'&(6.,(&0D,.02         "J"$ %&'(3(,'9)&).5(<.5*,.1(&C&*'-$
                                                                        !KN$ E,'6',(B,.B',*)'&(*.('50-',3*'/(<+3,3<*',(<13&&'&$
                                                                                                                                                             *)5'&$                                                                   "J>$ F5*'4,3*'(5.52E',1(<./'()5*.(C.0,(3BB1)<3*).5&(9)3(*+'(!6&%6'##S
                                                                        !K#$ @.5&)/',(-3*<+)54(3,D)*,3,C(;+)*'&B3<':(,3*+',(*+35(&B'<)6)<(;+)*'&2
                                                                                                                                                        "?!$ E,.9)/'(&'B3,3*'(,'3/(35/(;,)*'(3<<'&&.,&$                                    -./01'&$
                                                                              B3<'(<+3,3<*',&$
                                                                                                                                                        "?"$ O.5P*(0&'(19310'(3<<'&&.,&$                                              "JJ$ `''B(C.0,(<.56)40,3*).5(1354034'(05<.-B1)<3*'/$
                                                                        !K7$ T'(&B'<)6)<(;+'5(-3*<+)54(R3&(-0<+(3&(B.&&)D1'P$
                                                                        !M?$ %&'(<3B*0,)54(B3,'5*+'&'&(.51C(;+'5(C.0()5*'5/(*.(<3B*0,'$                 "?>$ O.5P*(0&'(*+'()5/),'<*(.D['<*(&C5*3A$                                    "JK$ O.5P*(0&'(-!(3/*&$
                                                                        !M!$ %&'(*+'(50-',)<(<3B*0,'(93,)3D1'&(.51C(;+'5(C.0P,'(&0,'(*+3*(*+'(          "?J$ E,.9)/'(35(.B*)-31()5*',63<':(,3*+',(*+35(3(-)5)-31(.5'$                 "JM$ O.5P*(*)#(93,)3D1'&(.,(6)1'+35/1'&$
                                                                              B,'<'/)54(-3*<+(&0<<''/'/$                                                "?K$ H9',1.3/(.51C(*+'()&.-.,B+)<(.B',3*.,&(.6(314'D,3)<(<13&&'&$             "JN$ O.5P*(D'(<1'9',$
                                                                        !M"$ L1;3C&(4)9'(<3B*0,'/(&0D&*,)54&(B,.B',(53-'&$                              "?M$ L1;3C&(<.5&)/',(.9',1.3/)54(*+'(D..1'35:(50-',)<:(35/(&*,)54(<.',2 "J#$ F6(C.0(-0&*(,'1C(.5(<1'9',5'&&:('5<3B&013*'()*$
                                                                        !M>$ U.='5)V'()5B0*(0&)54(*+'(=DH(6134$                                              <).5&(.6(.D['<*&$                                                        "J7$ O.5P*(.B*)-)V'(<./'(a(D'5<+-3,=()*$
                                                                        !MJ$ T0)1/(,'4013,('AB,'&&).5&(6,.-(*3D1'&$                                                                                                                   "K?$ O.5P*(.B*)-)V'(/3*3(&*,0<*0,'&(a(-'3&0,'(*+'-$
                                                                        !MK$ T0)1/(<.-B1'A(,'4013,('AB,'&&).5&(6,.-(&)-B1',(B)'<'&$                     Class Hierarchies                                                             "K!$ _..=(6.,(.BB.,*05)*)'&(*.(0&'(<3<+'&$
                                                                                                                                                                                                                                      "K"$ L0*.-3*'(C.0,(&0D,.0*)5'(<3<+)54$
                                                                        !MM$ @.5&)/',(0&)54(C'D'>1##;89986()5&*'3/(.6(;,)*)54(C.0,(.;5(
                                                                                                                                                        "?N$ O.5P*(-35)B013*'(*+'(1)&*(.6(D3&'(<13&&'&(/),'<*1C$                      "K>$ T'5<+-3,=(35C(<3<+)54(&*,3*'4C(C.0(0&'$
                                                                              ,'4'A'&$
                                                                                                                                                        "?#$ %&'(/)&*,)D0*'/('5<3B&013*'/(.D['<*&$                                    "KJ$ O.5P*(.B*)-)V'(3BB1)<3*).5&(a(B,.6)1'(*+'-$
                                                                        !MN$ L1;3C&(0&'(<+3,3<*',(<13&&'&()5&*'3/(.6(&)541'2<+3,3<*',(31*',53*).5&$
                                                                                                                                                        "?7$ 8'9',(0&'(*+'(.5'23,40-'5*(6.,-(.6(D1'&&$                                "KK$ T'(<3,'601(*.(B,'&',9'(&'-35*)<&(;+'5(,'63<*.,)54(&C5*3A$
                                                                        !M#$ W3<*.,(.0*(<.--.5(366)A'&(6,.-(31*',53*).5&$
                                                                                                                                                        "!?$ E3&&(<.5&*,0<*.,(3,40-'5*&(3&(13D'1'/(9310'&:(0&)54(3(+3&+(,'6',2
                                                                        !M7$ E,'9'5*(0&'1'&&(D3<=*,3<=)54$
                                                                                                                                                             '5<'$                                                                     !"#$%&"'(%!#)*(+*"'%,"-"#".*"%/0+1"%2"#'+3.%45645665
                                                                        !N?$ E,'6',(6)A'/2&*,)54(#1(<.-B3,)&.5&(*.(6)A'/2B3**',5(,'4'A(-3*<+'&$         "!!$ O)&*)540)&+(3,40-'5*&(6.,(D3&'(<13&&'&(DC(<13&&(53-'(3&(;'11$          !"#$%&"'(%!#)*(+*"'%78%,)-+).%/0.1)2
                                                                                                                                                    "!"$ I'B3,3*'(C.0,(<.5&*,0<*).5:()5)*)31)V3*).5:(35/(/'&*,0<*).5(B,.<'&&'&$     9%:66;%<=,"+$$8%>"1+)%?.*5@%A$$%#+BC('%#"'"#2"15
                                                                      Error Handling                                                                "!>$ T0)1/(*+'(&*35/3,/(<13&&()56,3&*,0<*0,'(30*.-3*)<311C$                     3"4"#".*"%56+7"%78%809).%:#0-).'
                                                                      !N!$ U+,.;('A<'B*).5&()5&*'3/(.6(,'*0,5)54(&B'<)31(9310'&(.,(&'**)54(6134&$   "!J$ %&'(;&:<<##/7I(*.(30*.-3*'(*+'(/'311.<3*).5(.6(3**,)D0*'(/3*3$             9%:66D%EF0+##"$%G3.'0$().*8@%A$$%#+BC('%#"'"#2"15
• Perl::Tidy - “Parses and beautifies perl
  source”
• Perl::Critic - “Critique Perl source code for
  best-practices”
Perl::Tidy
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
Perl::Tidy
use strict;
my @list = ( 'Emacs', 'Vi   ' );
my $rand = rand();
print "10 random users said:n";
foreach ( 0 .. 10 ) {
    my $i = int( $rand + rand() );
    print " $list[$i] users are from Venus" . ", "
        . "$list[1-$i] users are from Mars" . "n";
}
Perl::Tidy

• configurable (parameters or .perltidyrc)
• integrates with most text editors
• some people use it as an svn hook
Perl::Critic
use strict;
my @list=('Emacs', 'Vi    '); my $rand = rand();
print "10 random users said:n";
foreach(0..10) {
my $i=int ($rand+rand());
print " $list[$i] users are from Venus" . ", " .
"$list[1-$i] users are from Mars" .
"n";
}
Perl::Critic


Loop iterator is not lexical at line 5, column 1.
See page 108 of PBP. (Severity: 5)
Perl::Critic
• configurable (several severity levels,
  extendable, .perlcriticrc)
• integrates with most text editors
• some people also use it as an svn hook
• if you don’t own PBP, there’s also user-
  contributed documentation on each subject
Methods


• Pair programming
• Code review
Further documentation

• http://127h.sl.pt - An Introduction to Perl
  Critic, by Josh McAdams
• http://127i.sl.pt - Perl Tidy Perl Critic, by
  olegmmiller
• http://127w.sl.pt - Perl Best Practices
  Reference Guide

Introduction to Perl Best Practices

  • 1.
    Introduction to Perl BestPractices José Castro <cog@cpan.org> Tokyo, September 2009
  • 2.
    Who am I? •Perl Hacker from Portugal • COG@CPAN • YAPC::EU::20{04,05,06,07,08,09}, YAPC::NA::20{05,06,07,08}, YAPC::Asia 20{08,09}, LPW 20{04,05}, PPW 2008, OSDC::AU 2006 • Technology Evangelist @ SAPO SAPO/Portugal Telecom
  • 3.
  • 4.
  • 5.
    What is SAPO? •Older than Google, kind of like Yahoo!
  • 6.
    What is SAPO? •Older than Google, kind of like Yahoo! • 100+ techs
  • 7.
    What is SAPO? •Older than Google, kind of like Yahoo! • 100+ techs • 100+ non-techs
  • 8.
    What is SAPO? •Older than Google, kind of like Yahoo! • 100+ techs • 100+ non-techs • Mail, Blogs, Photos,Videos, Links, Cars, Real Estate, Jobs, Maps, Encyclopedia online, Search, Messaging, Social Network, etc., etc., etc.
  • 9.
    What do Ido at SAPO?
  • 10.
    What do Ido at SAPO? • Evangelism (motivation, productivity, quality)
  • 11.
    What do Ido at SAPO? • Evangelism (motivation, productivity, quality) • Organize the training program
  • 12.
    What do Ido at SAPO? • Evangelism (motivation, productivity, quality) • Organize the training program • Recruitment (lots of interviews every week)
  • 13.
    What do Ido at SAPO? • Evangelism (motivation, productivity, quality) • Organize the training program • Recruitment (lots of interviews every week) • Organize events
  • 14.
    What do Ido at SAPO? • Evangelism (motivation, productivity, quality) • Organize the training program • Recruitment (lots of interviews every week) • Organize events • Etc.
  • 15.
    Introduction to Perl BestPractices José Castro <cog@cpan.org> Tokyo, September 2009
  • 16.
    “What?” • a setof suggestions/guidelines to improve your code’s readability and reliability
  • 17.
    Disclaimer • what worksfor a particular situation may not be adequate for another • YMMV
  • 18.
    “Why?” • tomorrow, youmay need to fix a glitch in your code • next week, you may need to confirm something • 6 months from now, you may need to develop a new feature
  • 19.
    “How?” • using standards •defining your best practices and following them
  • 20.
  • 21.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 22.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 23.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 24.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 25.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 26.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 27.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 28.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 29.
    Block separation • Aprogram is a list of instructions • You’re writing it as a letter • Separate your paragraphs, for clarity
  • 30.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 31.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 32.
    Separate instructions • Eachinstruction should have its own line
  • 33.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 34.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 35.
    Indentation • 2 spaces? •4 spaces? • 6, 8? • Tabs?
  • 36.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 37.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 38.
    Spaces around operators • Don’t clutter things up • Spaces around operators help you find them more easily
  • 39.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 40.
    use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 41.
    use strict; my @list= ('Emacs', 'Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i = int ($rand + rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 42.
    Naming variables • Don’tname them “var”, “list”, “hash” or anything else that does not have a meaning • Make sure the name helps you identify what it is
  • 43.
    use strict; my @list= ('Emacs', 'Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i = int ($rand + rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 44.
    use strict; my @editors= ('Emacs', 'Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i = int ($rand + rand()); print " $editors[$i] users are from Venus" . ", "$editors[1-$i] users are from Mars" . "n"; }
  • 45.
    Vertical indentation • Verticalindentation helps your eyes find things more easily
  • 46.
    use strict; my @editors= ('Emacs', 'Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i = int ($rand + rand()); print " $editors[$i] users are from Venus" . ", "$editors[1-$i] users are from Mars" . "n"; }
  • 47.
    use strict; my @editors= ('Emacs', 'Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i = int ($rand + rand()); print " $editors[$i] users are from Venus" . ", "$editors[1-$i] users are from Mars" . "n"; }
  • 48.
  • 49.
    my @list =(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377, for my $number (@list) { if (grep{$number==$_}@list2) {print "$number is }
  • 50.
    my @list =(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377, for my $number (@list) { if (grep{$number==$_}@list2) {print "$number is }
  • 51.
    my @list =(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377, for my $number (@list) { if (grep{$number==$_}@list2) {print "$number is }
  • 52.
    my @list =(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377, for my $number (@list) { if (grep{$number==$_}@list2) {print "$number is }
  • 53.
    my @list =(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377, for my $number (@list) { if (grep{$number==$_}@list2) {print "$number is }
  • 54.
    2 is botha prime number and a fibonacci number 3 is both a prime number and a fibonacci number 5 is both a prime number and a fibonacci number 13 is both a prime number and a fibonacci number 89 is both a prime number and a fibonacci number
  • 55.
    Strict and warnings •both strict and warnings will help you avoid lots of pesky mistakes
  • 56.
    my @list =(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377, for my $number (@list) { if (grep{$number==$_}@list2) {print "$number is }
  • 57.
    use strict; use warnings; my@list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377, for my $number (@list) { if (grep{$number==$_}@list2) {print "$number is }
  • 58.
    Avoid lines over80 charac • code is easier to read if it fits on the screen • even if using line wrapping, having to figure out if two lines are different instructions or the same one is harder than not having to do it
  • 59.
    use strict; use warnings; my@list = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 my @list2 = (1,1,2,3,5,8,13,21,34,55,89,144,233,377, for my $number (@list) { if (grep{$number==$_}@list2) {print "$number is }
  • 60.
    use strict; use warnings; my@list = (2,3,5,7,11,13,17,19,23,29,31, 37,41,43,47,53,59,61,67,71,73,79,83,89,97,101) ; my @list2 = (1,1,2,3,5,8,13,21,34,55,89, 144,233,377,610,987,1597,2584,4181,6765) ; for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number and a }
  • 61.
    use strict; use warnings; my@list = (2,3,5,7,11,13,17,19,23,29,31, 37,41,43,47,53,59,61,67,71,73,79,83,89,97,101) ; my @list2 = (1,1,2,3,5,8,13,21,34,55,89, 144,233,377,610,987,1597,2584,4181,6765) ; for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " a }
  • 62.
    use strict; use warnings; my@list = (2,3,5,7,11,13,17,19,23,29,31, 37,41,43,47,53,59,61,67,71,73,79,83,89,97,101) ; my @list2 = (1,1,2,3,5,8,13,21,34,55,89, 144,233,377,610,987,1597,2584,4181,6765) ; for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 63.
    When breaking lines, align vertically • a broken line is a visual accident waiting to happen
  • 64.
    use strict; use warnings; my@list = (2,3,5,7,11,13,17,19,23,29,31, 37,41,43,47,53,59,61,67,71,73,79,83,89,97,101) ; my @list2 = (1,1,2,3,5,8,13,21,34,55,89, 144,233,377,610,987,1597,2584,4181,6765) ; for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 65.
    use strict; use warnings; my@list = (2,3,5,7,11,13,17,19,23,29,31, 37,41,43,47,53,59,61,67,71,73,79,83,89,9 my @list2 = (1,1,2,3,5,8,13,21,34,55,89, 144,233,377,610,987,1597,2584,4181,6765 for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 66.
    Add spaces aftera comma • spaces after a comma help you visually separate items
  • 67.
    use strict; use warnings; my@list = (2,3,5,7,11,13,17,19,23,29,31, 37,41,43,47,53,59,61,67,71,73,79,83,89,9 my @list2 = (1,1,2,3,5,8,13,21,34,55,89, 144,233,377,610,987,1597,2584,4181,6765 for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 68.
    use strict; use warnings; my@list = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, my @list2 = (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 41 for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 69.
    Organize long lists as tables • the brain identifies patterns such as tables much more easily
  • 70.
    use strict; use warnings; my@list = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, my @list2 = (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 41 for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 71.
    use strict; use warnings; my@list = ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, my @list2 = (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 41 for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 72.
    use strict; use warnings; my@list = ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, my @list2 = ( 1, 1, 2, 3, 5, 8, 13, 2 144, 233, 377, 610, 987, 1597, 2584, 41 for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 73.
    Again, name variables appropriately • the brain identifies patterns such as tables much more easily
  • 74.
    use strict; use warnings; my@list = ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, my @list2 = ( 1, 1, 2, 3, 5, 8, 13, 2 144, 233, 377, 610, 987, 1597, 2584, 41 for my $number (@list) { if (grep{$number==$_}@list2) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 75.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if (grep{$number==$_}@fibonnaci) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 76.
    Spaces for clarity •around operators • around blocks • around anything else that may cause confusion
  • 77.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if (grep{$number==$_}@fibonnaci) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 78.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 79.
    Block closing • theclosing curly brace should be in a line by itself • this helps better identify where the block ends
  • 80.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern"} }
  • 81.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern" } }
  • 82.
    Always end astatement with a semicolon • even if it’s the last statement in the block • even if the closing curly brace is on the same line • this will allow you to add another statement without having to check the line above
  • 83.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern" } }
  • 84.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern"; } }
  • 85.
    Inside a loop,use empty lines around the body • this is also going to help you identify the beginning and the end of the loop
  • 86.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern"; } }
  • 87.
    use strict; use warnings; my@prime_numbers = ( 2, 3, 5, 7, 11, 13, 17, 19, 37, 41, 43, 47, 53, 59, 61, 67, my @fibonnaci = ( 1, 1, 2, 3, 5, 8, 144, 233, 377, 610, 987, 1597, for my $number (@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern"; } }
  • 88.
  • 89.
    for my $number(@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern"; } }
  • 90.
    if ( grep{ $number == $_ } @fibonnaci ) {
  • 91.
    Using CPAN • Manymodules on CPAN already implement what we need in a far better way than we could possibly do in a couple of minutes
  • 92.
    grep { 2== $_ } ( 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946) if ( grep { $number == $_ } @fibonnaci ) {
  • 93.
    grep { 2== $_ } ( 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946) if ( grep { $number == $_ } @fibonnaci ) {
  • 94.
    grep { 2== $_ } ( 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946) if ( grep { $number == $_ } @fibonnaci ) {
  • 95.
    grep { 2== $_ } ( 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946) if ( grep { $number == $_ } @fibonnaci ) {
  • 96.
    grep { 2== $_ } ( 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946) if ( grep { $number == $_ } @fibonnaci ) {
  • 97.
    grep { 2== $_ } ( 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946) if ( grep { $number == $_ } @fibonnaci ) {
  • 98.
    grep { 2== $_ } ( 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946) n iterations, always if ( grep { $number == $_ } @fibonnaci ) {
  • 99.
    if ( grep{ $number == $_ } @fibonnaci ) {
  • 100.
    use List::MoreUtils qw(any); if( grep { $number == $_ } @fibonnaci ) {
  • 101.
    use List::MoreUtils qw(any); if( any { $number == $_ } @fibonnaci ) {
  • 102.
    Structure • separate yourcode in subroutines • subroutines should have meaningful names
  • 103.
    use List::MoreUtils qw(any); if( any { $number == $_ } @fibonnaci ) {
  • 104.
    use List::MoreUtils qw(any); if( is_fibonnaci($number) ) { sub is_fibonnaci { my $number = shift; return any { $number == $_ } @fibonnaci }
  • 105.
    for my $number(@prime_numbers) { if ( grep { $number == $_ } @fibonnaci ) { print "$number is both a prime number " . " and a fibonacci numbern"; } }
  • 106.
    for my $number(@prime_numbers) { if ( is_fibonnaci($number) ) { print "$number is both a prime number " . " and a fibonacci numbern"; } }
  • 107.
    for my $number(@prime_numbers) { if ( is_fibonnaci($number) ) { print "$number is both a prime number " . " and a fibonacci numbern"; } } sub is_fibonnaci { my $number = shift; return any { $number == $_ } @fibonnaci;
  • 108.
    for my $number(@prime_numbers) { if ( is_fibonnaci($number) ) { print "$number is both a prime number " . " and a fibonacci numbern"; } }
  • 109.
    for (@prime_numbers) { if ( is_fibonnaci($_) ) { print "$_ is both a prime number " . " and a fibonacci numbern"; } }
  • 110.
  • 111.
    for ( 1.. 1000000000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 112.
    for ( 1.. 1000000000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 113.
    for ( 1.. 1000000000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 114.
    for ( 1.. 1000000000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 115.
    for ( 1.. 1000000000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 116.
    for ( 1.. 1000000000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 117.
    Underscores for large numbers • Large numbers are hard to read • Underscores every three digits can help
  • 118.
    for ( 1.. 1000000000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 119.
    for ( 1.. 1_000_000_000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 120.
    Booleans • flags shouldn’tbe named “flag” • they should have intuitive names
  • 121.
    for ( 1.. 1_000_000_000 ) { my $flag = 1; $flag = 0 if is_prime( $_ ); $flag = 0 if is_fibonnaci( $_ ); if ( $flag ) { print "$_ seems interestingn"; } }
  • 122.
    for ( 1.. 1_000_000_000 ) { my $is_interesting = 1; $is_interesting = 0 if is_prime( $_ ); $is_interesting = 0 if is_fibonnaci( $_ ); if ( $is_interesting ) { print "$_ seems interestingn"; } }
  • 123.
  • 125.
    Perl Best Practices @M" I.'(9)*'$.&8$'.(,8(/=+$8C'(,-'($'%*%?/5/,4(8<(58)>()9=?'$." DO" X%4(89,(=95,/5/)'(.,$/)>.(8C'$(=95,/+5'(5/)'." Documentation D!" I.'(%(-'$'*8&(;-')(%(=95,/5/)'(.,$/)>('G&''*.(,;8(5/)'." LF" A/.,/)>9/.-(9.'$(*8&9='),%,/8)(<$8=(,'&-)/&%5(*8&9='),%,/8)" D6" I.'(%(E,-'$'*8&B(;-')(%(-'$'*8&(;895*(&8=+$8=/.'(489$(/)*'),%N LH" S$'%,'(.,%)*%$*(K_A(,'=+5%,'.(<8$(=8*95'.(%)*(%++5/&%,/8)." Reference Guide D@" ,/8)" W%:'('C'$4(-'$'*8&(,'$=/)%,8$(%(./)>5'(9++'$&%.'(/*'),/</'$(;/,-(%( LJ" LL" VG,')*(%)*(&9.,8=/0'(489$(.,%)*%$*(K_A(,'=+5%,'." K9,(9.'$(*8&9='),%,/8)(/)(.89$&'(</5'." .,%)*%$*(+$'</G" LM" 1''+(%55(9.'$(*8&9='),%,/8)(/)(%(./)>5'(+5%&'(;/,-/)(489$(.89$&'( DD" Y-')(/),$8*9&/)>(%(-'$'*8&Q(Z98,'(,-'(,'$=/)%,8$" </5'" Code Layout DF" A8)B,(9.'(?%$';8$*." MO" K5%&'(K_A(%.(&58.'(%.(+8../?5'(,8(,-'(')*(8<(,-'(</5'" DH" 3'.'$C'(#$(<8$(+%/$." M!" 79?*/C/*'(489$(,'&-)/&%5(*8&9='),%,/8)(%++$8+$/%,'54" !" #$%&'(%)*(+%$'),-'./0'(/)(123(.,45'" DJ" A8)B,(9.'(&8==%.(,8(.'Z9')&'(.,%,'='),." M6" I.'(?58&:(,'=+5%,'.(<8$(=%^8$(&8=='),." 6" 7'+%$%,'(489$(&8),$85(:'4;8$*.(<$8=(,-'(<8558;/)>(8+')/)>( DL" A8)B,(=/G(-/>-N(%)*(58;N+$'&'*')&'(?885'%)." M@" I.'(<955N5/)'(&8=='),.(,8('G+5%/)(,-'(%5>8$/,-=" ?$%&:'," DM" K%$'),-'./0'('C'$4($%;(5/.," MD" I.'(')*N8<N5/)'(&8=='),.(,8(+8/),(89,(.9?,5',/'.(%)*(8**/,/'." @" A8)B,(.'+%$%,'(.9?$89,/)'(8$(C%$/%?5'()%='.(<$8=(,-'(<8558;/)>( FO" I.'(,%?5'N588:9+(,8(,'.,(<8$(='=?'$.-/+(/)(5/.,.(8<(.,$/)>.[(9.'(+),%&' MF" S8=='),(%)4,-/)>(,-%,(-%.(+9005'*(8$(,$/&:'*(489" 8+')/)>(?$%&:'," <8$(='=?'$.-/+(8<(5/.,.(8<(%)4,-/)>('5.'" MH" S8)./*'$(;-',-'$(/,B.(?',,'$(,8($';$/,'(,-%)(,8(&8==')," D" A8)B,(9.'(9))'&'..%$4(+%$'),-'.'.(<8$(?9/5,/).(%)*(E-8)8$%$4B( MJ" I.'(E/)C/./?5'B(K_A(.'&,/8).(<8$(58)>'$(,'&-)/&%5(*/.&9../8)." ?9/5,/)." F" 7'+%$%,'(&8=+5'G(:'4.(8$(/)*/&'.(<$8=(,-'/$(.9$$89)*/)>(?$%&:',." Variables ML" S-'&:(,-'(.+'55/)>Q(.4),%GQ(%)*(.%)/,4(8<(489$(*8&9='),%,/8)" H" I.'(;-/,'.+%&'(,8(-'5+(?/)%$4(8+'$%,8$.(.,%)*(89,(<$8=(,-'/$( F!" TC8/*(9./)>()8)N5'G/&%5(C%$/%?5'." 8+'$%)*." F6" A8)B,(9.'(+%&:%>'(C%$/%?5'.(/)(489$(8;)(*'C'58+=')," Built-in Functions J" K5%&'(%(.'=/&858)(%<,'$('C'$4(.,%,'=')," F@" P<(489B$'(<8$&'*(,8(=8*/<4(%(+%&:%>'(C%$/%?5'Q("('+"/0'(/," MM" A8)B,($'&8=+9,'(.8$,(:'4.(/)./*'(%(#(%*" L" K5%&'(%(&8==%(%<,'$('C'$4(C%59'(/)(%(=95,/5/)'(5/.," !OO" I.'(%!8!%#!(,8($'C'$.'(%(5/.," FD" P)/,/%5/0'(%)4(C%$/%?5'(489("('+"/0'" M" I.'(JLN&859=)(5/)'." FF" -#!./)0"1#2(<8$(,-'(5'..(<%=/5/%$(+9)&,9%,/8)(C%$/%?5'." !O!" I.'(.&%5%$(%!8!%#!(,8($'C'$.'(%(.&%5%$" !O" I.'(<89$N&859=)(/)*'),%,/8)(5'C'5." FH" P<(489B$'(<8$&'*(,8(=8*/<4(%(+9)&,9%,/8)(C%$/%?5'Q("('+"/0'(/," !O6" I.'(-)5+'9 (,8('G,$%&,(</G'*N;/*,-(</'5*." !!" P)*'),(;/,-(.+%&'.Q()8,(,%?." !6" R'C'$(+5%&'(,;8(.,%,'='),.(8)(,-'(.%='(5/)'" FJ" A8)B,(9.'(,-'($'>'G(=%,&-(C%$/%?5'." !O@" I.'(#5"1*(,8('G,$%&,(./=+5'(C%$/%?5'N;/*,-(</'5*." !@" S8*'(/)(+%$%>$%+-." FL" #';%$'(8<(%)4(=8*/</&%,/8)(C/%(()" !OD" I.'(*+,-../01)20(,8('G,$%&,(&8=+5'G(C%$/%?5'N;/*,-(</'5*." !D" A8)B,(&9**5'(%)(!"#!" FM" I.'()'>%,/C'(/)*/&'.(;-')(&89),/)>(<$8=(,-'(')*(8<(%)(%$$%4" !OF" TC8/*(.,$/)>(!8+"" HO" %:'(%*C%),%>'(8<(-%.-(%)*(%$$%4(.5/&/)>" !OH" S8)./*'$(?9/5*/)>(489$(.8$,/)>($89,/)'.(;/,-(034-..567+4" !F" T5/>)(&8$$'.+8)*/)>(/,'=.(C'$,/&%554" H!" I.'(%(,%?95%$(5%489,(<8$(.5/&'." !OJ" I.'(DN%$>(#-:#*%(/).,'%*(8<(5C%59'(#-:#*%" !H" #$'%:(58)>('G+$'../8).(?'<8$'(%)(8+'$%,8$" H6" U%&,8$(5%$>'(:'4(8$(/)*'G(5/.,.(89,(8<(,-'/$(.5/&'." !OL" W%:'(%++$8+$/%,'(9.'(8<(5C%59'(C%59'." !J" U%&,8$(89,(58)>('G+$'../8).(/)(,-'(=/**5'(8<(.,%,'='),." !L" T5;%4.(?$'%:(%(58)>('G+$'../8)(%,(,-'(8+'$%,8$(8<(,-'(58;'.,(+8../N !OM" I.'(0"(:Q()8,(8]$" ?5'(+$'&'*')&'" Control Structures !!O" TC8/*(%($%;(#!"!'*(<8$()8)N/),'>'$(.5''+." !M" #$'%:(58)>(%../>)='),.(?'<8$'(,-'(%../>)='),(8+'$%,8$" !!!" T5;%4.(9.'(%(?58&:(;/,-(%(4+5(%)*(0%!5" H@" I.'(?58&:(1&Q()8,(+8.,</G(1&" !!6" I.'(,-'(E)8)N?9/5,/)(?9/5,/).B" 6O" U8$=%,(&%.&%*'*(,'$)%$4(8+'$%,8$.(/)(&859=)." HD" 3'.'$C'(+8.,</G(1&(<8$(<58;N8<N&8),$85(.,%,'='),." 6!" K%$'),-'./0'(58)>(5/.,." HF" A8)B,(9.'(+8.,</G(-)"!##Q(&(%Q(321"!Q(8$(-)*1"" 66" V)<8$&'(489$(&-8.')(5%489,(.,45'(='&-%)/&%554" HH" A8)B,(9.'(-)"!##(8$(-)*1"(%,(%55" Subroutines HJ" TC8/*(SN.,45'(&(%(.,%,'='),." !!@" S%55(.9?$89,/)'.(;/,-(+%$'),-'.'.(?9,(;/,-89,(%(5'%*/)>(9" Naming Conventions HL" TC8/*(.9?.&$/+,/)>(%$$%4.(8$(-%.-'.(;/,-/)(588+." !!D" A8)B,(>/C'(.9?$89,/)'.(,-'(.%='()%='.(%.(?9/5,N/)(<9)&,/8)." 6@" I.'(>$%==%,/&%5(,'=+5%,'.(;-')(<8$=/)>(/*'),/</'$." HM" R'C'$(.9?.&$/+,(=8$'(,-%)(8)&'(/)(%(588+" !!F" T5;%4.(9)+%&:(:)(</$.," 6D" R%='(?885'%).(%<,'$(,-'/$(%..8&/%,'*(,'.," JO" I.'()%='*(5'G/&%5.(%.('G+5/&/,(&(%(588+(/,'$%,8$." !!H" I.'(%(-%.-(8<()%='*(%$>9='),.(<8$(%)4(.9?$89,/)'(,-%,(-%.(=8$'( 6F" W%$:(C%$/%?5'.(,-%,(.,8$'($'<'$')&'.(;/,-(%($%!&(.9<</G" J!" T5;%4.(*'&5%$'(%(&(%(588+(/,'$%,8$(C%$/%?5'(;/,-(4," ,-%)(,-$''(+%$%=','$." 6H" R%='(%$$%4.(/)(,-'(+59$%5(%)*(-%.-'.(/)(,-'(./)>95%$" J6" I.'(4+5(/).,'%*(8<(&(%(;-')(>')'$%,/)>()';(5/.,.(<$8=(85*" !!J" I.'(6!&1)!6)'..(8$(!71#*')&'(,8(,'.,(<8$(=/../)>(%$>9='),." 6J" I.'(9)*'$.&8$'.(,8(.'+%$%,'(;8$*.(/)(=95,/;8$*(/*'),/</'$." J@" I.'(0%!5(%)*(&1%#*(/).,'%*(8<(&(%(;-')(.'%$&-/)>(<8$(C%59'.(/)(%(5/.," !!L" 3'.85C'(%)4(*'<%95,(%$>9='),(C%59'.(%.(.88)(%.(:)(/.(9)+%&:'*" 6L" A/.,/)>9/.-(*/<<'$'),(+$8>$%=(&8=+8)'),.(?4(&%.'" JD" I.'(&(%(/).,'%*(8<(4+5(;-')(,$%).<8$=/)>(%(5/.,(/)(+5%&'" !!M" T5;%4.($',9$)(.&%5%$(/)(.&%5%$($',9$)." 6M" T??$(/*'),.(?4(+$'<G" JF" I.'(%(.9?$89,/)'(&%55(,8(<%&,8$(89,(&8=+5'G(5/.,(,$%).<8$=%,/8)." !6O" W%:'(5/.,N$',9$)/)>(.9?$89,/)'.($',9$)(,-'(E8?C/89.B(C%59'(/)(.&%5%$( @O" T??$'C/%,'(8)54(;-')(,-'(='%)/)>($'=%/).(9)%=?/>989." JH" R'C'$(=8*/<4(()(/)(%(5/.,(<9)&,/8)" &8),'G," @!" TC8/*(9./)>(/)-'$'),54(%=?/>989.(;8$*.(/)()%='." JJ" TC8/*(&%.&%*/)>(%)(1&" !6!" Y-')(,-'$'(/.()8(E8?C/89.B(.&%5%$(&8),'G,($',9$)(C%59'Q(&8)./*'$( @6" K$'</G(E<8$(/),'$)%5(9.'(8)54B(.9?$89,/)'.(;/,-(%)(9)*'$.&8$'" JL" I.'(,%?5'(588:N9+(/)(+$'<'$')&'(,8(&%.&%*'*('Z9%5/,4(,'.,." /3;-+,-<6=..>+-<4;(/).,'%*" JM" Y-')(+$8*9&/)>(%(C%59'Q(9.'(,%?95%$(,'$)%$/'." !66" A8)B,(9.'(.9?$89,/)'(+$8,8,4+'." T5;%4.($',9$)(C/%(%)('G+5/&/,(%!*-%)" Values and Expressions LO" A8)B,(9.'(6(]321"!(588+." !6@" !6D" I.'(%(?%$'(%!*-%)(,8($',9$)(<%/59$'" L!" 3'^'&,(%.(=%)4(/,'$%,/8).(%.(+8../?5'Q(%.('%$54(%.(+8../?5'" @@" I.'(/),'$+85%,/)>(.,$/)>(*'5/=/,'$.(8)54(<8$(.,$/)>.(,-%,(%&,9%554(/),'$N L6" A8)B,(&8),8$,(588+(.,$9&,9$'.(^9.,(,8(&8).85/*%,'(&8),$85" +85%,'" @D" A8)B,(9.'(!!(8$(""(<8$(%)('=+,4(.,$/)>" L@" I.'(&(%(%)*(%!6((/).,'%*(8<(%)(/$$'>95%$54(&89),'*(321"!" I/O LD" X%?'5('C'$4(588+(,-%,(/.('G/,'*('G+5/&/,54Q(%)*(9.'(,-'(5%?'5(;/,-( @F" A8)B,(;$/,'(8)'N&-%$%&,'$(.,$/)>.(/)(C/.9%554(%=?/>989.(;%4." !6F" A8)B,(9.'(?%$';8$*(</5'-%)*5'." 'C'$4()!7*Q("+#*Q(8$(%!6(" !6H" I.'(/)*/$'&,(</5'-%)*5'." @H" I.'()%='*(&-%$%&,'$('.&%+'.(/).,'%*(8<()9='$/&('.&%+'." @J" I.'()%='*(&8).,%),.Q(?9,(*8)B,(9.'('()#*+)*" !6J" P<(489(-%C'(,8(9.'(%(+%&:%>'(</5'-%)*5'Q("('+"/0'(/,(</$.," @L" A8)B,(+%*(*'&/=%5()9=?'$.(;/,-(5'%*/)>(0'$8."
  • 126.
    Perl Best Practices @M" I.'(9)*'$.&8$'.(,8(/=+$8C'(,-'($'%*%?/5/,4(8<(58)>()9=?'$." DO" X%4(89,(=95,/5/)'(.,$/)>.(8C'$(=95,/+5'(5/)'." Documentation D!" I.'(%(-'$'*8&(;-')(%(=95,/5/)'(.,$/)>('G&''*.(,;8(5/)'." LF" A/.,/)>9/.-(9.'$(*8&9='),%,/8)(<$8=(,'&-)/&%5(*8&9='),%,/8)" D6" I.'(%(E,-'$'*8&B(;-')(%(-'$'*8&(;895*(&8=+$8=/.'(489$(/)*'),%N LH" S$'%,'(.,%)*%$*(K_A(,'=+5%,'.(<8$(=8*95'.(%)*(%++5/&%,/8)." Reference Guide D@" ,/8)" W%:'('C'$4(-'$'*8&(,'$=/)%,8$(%(./)>5'(9++'$&%.'(/*'),/</'$(;/,-(%( LJ" LL" VG,')*(%)*(&9.,8=/0'(489$(.,%)*%$*(K_A(,'=+5%,'." K9,(9.'$(*8&9='),%,/8)(/)(.89$&'(</5'." .,%)*%$*(+$'</G" LM" 1''+(%55(9.'$(*8&9='),%,/8)(/)(%(./)>5'(+5%&'(;/,-/)(489$(.89$&'( DD" Y-')(/),$8*9&/)>(%(-'$'*8&Q(Z98,'(,-'(,'$=/)%,8$" </5'" Code Layout DF" A8)B,(9.'(?%$';8$*." MO" K5%&'(K_A(%.(&58.'(%.(+8../?5'(,8(,-'(')*(8<(,-'(</5'" DH" 3'.'$C'(#$(<8$(+%/$." M!" 79?*/C/*'(489$(,'&-)/&%5(*8&9='),%,/8)(%++$8+$/%,'54" !" #$%&'(%)*(+%$'),-'./0'(/)(123(.,45'" DJ" A8)B,(9.'(&8==%.(,8(.'Z9')&'(.,%,'='),." M6" I.'(?58&:(,'=+5%,'.(<8$(=%^8$(&8=='),." 6" 7'+%$%,'(489$(&8),$85(:'4;8$*.(<$8=(,-'(<8558;/)>(8+')/)>( DL" A8)B,(=/G(-/>-N(%)*(58;N+$'&'*')&'(?885'%)." M@" I.'(<955N5/)'(&8=='),.(,8('G+5%/)(,-'(%5>8$/,-=" ?$%&:'," DM" K%$'),-'./0'('C'$4($%;(5/.," MD" I.'(')*N8<N5/)'(&8=='),.(,8(+8/),(89,(.9?,5',/'.(%)*(8**/,/'." @" A8)B,(.'+%$%,'(.9?$89,/)'(8$(C%$/%?5'()%='.(<$8=(,-'(<8558;/)>( FO" I.'(,%?5'N588:9+(,8(,'.,(<8$(='=?'$.-/+(/)(5/.,.(8<(.,$/)>.[(9.'(+),%&' MF" S8=='),(%)4,-/)>(,-%,(-%.(+9005'*(8$(,$/&:'*(489" 8+')/)>(?$%&:'," <8$(='=?'$.-/+(8<(5/.,.(8<(%)4,-/)>('5.'" MH" S8)./*'$(;-',-'$(/,B.(?',,'$(,8($';$/,'(,-%)(,8(&8==')," D" A8)B,(9.'(9))'&'..%$4(+%$'),-'.'.(<8$(?9/5,/).(%)*(E-8)8$%$4B( MJ" I.'(E/)C/./?5'B(K_A(.'&,/8).(<8$(58)>'$(,'&-)/&%5(*/.&9../8)." ?9/5,/)." F" 7'+%$%,'(&8=+5'G(:'4.(8$(/)*/&'.(<$8=(,-'/$(.9$$89)*/)>(?$%&:',." Variables ML" S-'&:(,-'(.+'55/)>Q(.4),%GQ(%)*(.%)/,4(8<(489$(*8&9='),%,/8)" H" I.'(;-/,'.+%&'(,8(-'5+(?/)%$4(8+'$%,8$.(.,%)*(89,(<$8=(,-'/$( F!" TC8/*(9./)>()8)N5'G/&%5(C%$/%?5'." 8+'$%)*." F6" A8)B,(9.'(+%&:%>'(C%$/%?5'.(/)(489$(8;)(*'C'58+=')," Built-in Functions J" K5%&'(%(.'=/&858)(%<,'$('C'$4(.,%,'=')," F@" P<(489B$'(<8$&'*(,8(=8*/<4(%(+%&:%>'(C%$/%?5'Q("('+"/0'(/," MM" A8)B,($'&8=+9,'(.8$,(:'4.(/)./*'(%(#(%*" L" K5%&'(%(&8==%(%<,'$('C'$4(C%59'(/)(%(=95,/5/)'(5/.," !OO" I.'(%!8!%#!(,8($'C'$.'(%(5/.," FD" P)/,/%5/0'(%)4(C%$/%?5'(489("('+"/0'" M" I.'(JLN&859=)(5/)'." FF" -#!./)0"1#2(<8$(,-'(5'..(<%=/5/%$(+9)&,9%,/8)(C%$/%?5'." !O!" I.'(.&%5%$(%!8!%#!(,8($'C'$.'(%(.&%5%$" !O" I.'(<89$N&859=)(/)*'),%,/8)(5'C'5." !"#$ %&'(')*+',(*+'(!"##$%&'(-./01'(.,(*+'(*+,''23,40-'5*(6.,-(.6(/0'(/," !N"$ X3='(63)1'/(D0)1*)5&(*+,.;('A<'B*).5&(*..$ "!K$ Y39'(3**,)D0*'&()5)*)31)V'/(35/(9',)6)'/(30*.-3*)<311C$ FH" P<(489B$'(<8$&'*(,8(=8*/<4(%(+9)&,9%,/8)(C%$/%?5'Q("('+" !O6" I.'(-)5+'9 (,8('G,$%&,(</G'*N;/*,-(</'5*." !!" P)*'),(;/,-(.+%&'.Q()8,(,%?." !"#$$ A8)B,(9.'(,-'($'>'G(=%,&-(C%$/%?5'." !N>$ X3='(63)10,'&(63*31()5(311(<.5*'A*&$ "!M$ IB'<)6C(<.',<).5&(3&(#/3C!5J!$K:(#5LMNC!$K:(35/(#O""P!$K(-'*+./&$ !6" R'C'$(+5%&'(,;8(.,%,'='),.(8)(,-'(.%='(5/)'" FJ" !O@" I.'(#5"1*(,8('G,$%&,(./=+5'(C%$/%?5'N;/*,-(</'5*." !"7$ 8'9',(!"#$:(%&!'#:(.,("()$*(*.(3(6)1'(;)*+.0*(<+'<=)54(*+'(.0*<.-'$ !NJ$ T'(<3,'601(;+'5(*'&*)54(6.,(63)10,'(.6(*+'('2'*#3(D0)1*)5$ FL" #';%$'(8<(%)4(=8*/</&%,/8)(C/%(()" !OD" I.'(*+,-../01)20(,8('G,$%&,(&8=+5'G(C%$/%?5'N;/*,-(</'5*." "!N$ %&'(#;LMLP@3!QN(-'*+./&()5&*'3/(.6(/L,NC##(<311&$ !@" S8*'(/)(+%$%>$%+-." "!#$ O.5P*(0&'(@L3"P"@4(+$ !>?$ FM" I.'()'>%,/C'(/)*/&'.(;-')(&89),/)>(<$8=(,-'(')*(8<(%)(%$$%4" !NK$ U+,.;('A<'B*).5&(.5(311(63)10,'&:()5<10/)54(,'<.9',3D1'(.5'&$ @1.&'(6)1'+35/1'&('AB1)<)*1C:(35/(3&(&..5(3&(B.&&)D1'$ !OF" TC8/*(.,$/)>(!8+"" !D" A8)B,(&9**5'(%)(!"#!" !>!$ %&'(+,)&#(()*+:(5.*(-!((()*+$ !NM$ Y39'('A<'B*).5&(,'B.,*(6,.-(*+'(<311',Z&(1.<3*).5:(5.*(6,.-(*+'(B13<'( HO" %:'(%*C%),%>'(8<(-%.-(%)*(%$$%4(.5/&/)>" !OH" S8)./*'$(?9/5*/)>(489$(.8$,/)>($89,/)'.(;/,-(034-..567+4" !F" T5/>)(&8$$'.+8)*/)>(/,'=.(C'$,/&%554" !H" #$'%:(58)>('G+$'../8).(?'<8$'(%)(8+'$%,8$" !>"$ E,'6',(1)5'2D3&'/(FGH(*.(&10,B)54$ H!" I.'(%(,%?95%$(5%489,(<8$(.5/&'." ;+','(*+'C(;','(*+,.;5$ !OJ" I.'(DN%$>(#-:#*%(/).,'%*(8<(5C%59'(#-:#*%" Modules !>>$ I10,B(3(6)1'+35/1'(;)*+(3(.!(D1.<=(6.,(B0,)*C$ H6" U%&,8$(5%$>'(:'4(8$(/)*'G(5/.,.(89,(8<(,-'/$(.5/&'." !NN$ @.-B.&'(',,.,(-'&&34'&()5(*+'(,'<)B)'5*P&(/)31'<*$ !OL" W%:'(%++$8+$/%,'(9.'(8<(5C%59'(C%59'." !J" U%&,8$(89,(58)>('G+$'../8).(/)(,-'(=/**5'(8<(.,%,'='),." !N#$ O.<0-'5*('9',C(',,.,(-'&&34'()5(*+'(,'<)B)'5*P&(/)31'<*$ "!7$ O'&)45(*+'(-./01'P&()5*',63<'(6),&*$ !>J$ I10,B(3(&*,'3-(;)*+(,'-&.##/&0-1(6.,(B.;',(35/(&)-B1)<)*C$ !OM" I.'(0"(:Q()8,(8]$" !L" T5;%4.(?$'%:(%(58)>('G+$'../8)(%,(,-'(8+'$%,8$(8<(,-'(58;'.,(+8../N !N7$ %&'('A<'B*).5(.D['<*&(;+'5'9',(63)10,'(/3*3(5''/&(*.(D'(<.59'C'/( ""?$ E13<'(.,)4)531(<./'()51)5'$(E13<'(/0B1)<3*'/(<./'()5(3(&0D,.0*)5'$( !>K$ L9.)/(0&)54((2/34!5:(051'&&(C.0(,'311C(-'35()*$ ?5'(+$'&'*')&'" !>M$ Control Structures L1;3C&(B0*(6)1'+35/1'&()5(D,3<'&(;)*+)5(35C(1-%67(&*3*'-'5*$ !!O" TC8/*(%($%;(#!"!'*(<8$()8)N/),'>'$(.5''+." *.(3(+35/1',$ E13<'(/0B1)<3*'/(&0D,.0*)5'&()5(3(-./01'$ !M" #$'%:(58)>(%../>)='),.(?'<8$'(,-'(%../>)='),(8+'$%,8$" !!!" T5;%4.(9.'(%(?58&:(;/,-(%(4+5(%)*(0%!5" !#?$ %&'('A<'B*).5(.D['<*&(;+'5(',,.,(-'&&34'&(-3C(<+354'$ ""!$ %&'(*+,''2B3,*(9',&).5(50-D',&$ !>N$ H@" I.'(?58&:(1&Q()8,(+8.,</G(1&" L1;3C&(B,.-B*(6.,()5*',3<*)9'()5B0*$ !!6" I.'(,-'(E)8)N?9/5,/)(?9/5,/).B" 6O" U8$=%,(&%.&%*'*(,'$)%$4(8+'$%,8$.(/)(&859=)." !#!$ %&'('A<'B*).5(.D['<*&(;+'5(*;.(.,(-.,'('A<'B*).5&(3,'(,'13*'/$ """$ 56.,<'(C.0,(9',&).5(,'^0),'-'5*&(B,.4,3--3*)<311C$ !>#$ O.5P*(,')59'5*(*+'(&*35/3,/(*'&*(6.,()5*',3<*)9)*C$ HD" 3'.'$C'(+8.,</G(1&(<8$(<58;N8<N&8),$85(.,%,'='),." 6!" K%$'),-'./0'(58)>(5/.,." !#"$ @3*<+('A<'B*).5(.D['<*&()5(-.&*2/',)9'/26),&*(.,/',$ "">$ AB.,*([0/)<).0&1C(35/:(;+','(B.&&)D1':(.51C(DC(,'^0'&*$ !>7$ %&'(*+'(A8)B,(9.'(+8.,</G(-)"!##Q(&(%Q(321"!Q(8$(-)*1"" HF" !"##,-8917(-./01'(6.,(B,.-B*)54$ 66" V)<8$&'(489$(&-8.')(5%489,(.,45'(='&-%)/&%554" !J?$ L1;3C&(<.59'C(*+'(B,.4,'&&(.6(1.54(5.52)5*',3<*)9'(.B',3*).5&( HH" A8)B,(9.'(-)"!##(8$(-)*1"(%,(%55" Subroutines !#>$ T0)1/('A<'B*).5(<13&&'&(30*.-3*)<311C$ ""J$ @.5&)/',('AB.,*)54(/'<13,3*)9'1C$ !#J$ %5B3<=(*+'('A<'B*).5(93,)3D1'()5('A*'5/'/('A<'B*).5(+35/1',&$ 9" ""K$ 8'9',(-3='(93,)3D1'&(B3,*(.6(3(-./01'P&()5*',63<'$ ;)*+)5()5*',3<*)9'(3BB1)<3*).5&$ HJ" TC8/*(SN.,45'(&(%(.,%,'='),." !!@" S%55(.9?$89,/)'.(;/,-(+%$'),-'.'.(?9,(;/,-89,(%(5'%*/)>( Naming Conventions !J!$ @.5&)/',(0&)54(*+'(/9:-7##;899'67<(-./01'(*.(30*.-3*'(C.0,( HL" TC8/*(.9?.&$/+,/)>(%$$%4.(8$(-%.-'.(;/,-/)(588+." ""M$ T0)1/(5';(-./01'(6,3-';.,=&(30*.-3*)<311C$ !!D" A8)B,(>/C'(.9?$89,/)'.(,-'(.%='()%='.(%.(?9/5,N/)(<9)&,/8)." ""N$ %&'(<.,'(-./01'&(;+','9',(B.&&)D1'$ 6@" I.'(>$%==%,/&%5(,'=+5%,'.(;-')(<8$=/)>(/*'),/</'$." B,.4,'&&()5/)<3*.,&$ HM" R'C'$(.9?.&$/+,(=8$'(,-%)(8)&'(/)(%(588+" Command-Line Processing !!F" T5;%4.(9)+%&:(:)(</$.," ""#$ %&'(@EL8(-./01'&(;+','(6'3&)D1'$ 6D" R%='(?885'%).(%<,'$(,-'/$(%..8&/%,'*(,'.," !J"$ L9.)/(3(,3;('#&#%*(;+'5(&'**)54(30*.610&+'&$ JO" I.'()%='*(5'G/&%5.(%.('G+5/&/,(&(%(588+(/,'$%,8$." !!H" I.'(%(-%.-(8<()%='*(%$>9='),.(<8$(%)4(.9?$89,/)'(,-%,(-%.(=8$'( !#K$ 56.,<'(3(&)541'(<.5&)&*'5*(<.--35/21)5'(&*,0<*0,'$ 6F" W%$:(C%$/%?5'.(,-%,(.,8$'($'<'$')&'.(;/,-(%($%!&(.9<</G" J!" T5;%4.(*'&5%$'(%(&(%(588+(/,'$%,8$(C%$/%?5'(;/,-(4," ,-%)(,-$''(+%$%=','$." !!J" I.'(6!&1)!6)'..(8$(!71#*')&'(,8(,'.,(<8$(=/../)>(%$>9='),." Testing and Debugging !#M$ L/+','(*.(3(&*35/3,/(&'*(.6(<.59'5*).5&()5(C.0,(<.--35/21)5'(&C52 6H" R%='(%$$%4.(/)(,-'(+59$%5(%)*(-%.-'.(/)(,-'(./)>95%$" References (/).,'%*(8<(&(%(;-')(>')'$%,/)>()';(5/.,.(<$8=(85*" J6" I.'(4+5 *3A$ 6J" I.'(9)*'$.&8$'.(,8(.'+%$%,'(;8$*.(/)(=95,/;8$*(/*'),/</'$." !#N$ !!L" 3'.85C'(%)4(*'<%95,(%$>9='),(C%59'.(%.(.88)(%.(:)(/.(9)+%&:'*"""7$ Q,)*'(*+'(*'&*(<3&'&(6),&*$ J@" I.'(0%!5(%)*(&1%#*(/).,'%*(8<(&(%(;-')(.'%$&-/)>(<8$(C%59'.(/)(%(5/.," I*35/3,/)V'(C.0,(-'*32.B*).5&$ !J>$ Q+','9',(B.&&)D1':(/','6','5<'(;)*+(3,,.;&$ !!M" T5;%4.($',9$)(.&%5%$(/)(.&%5%$($',9$)." 6L" A/.,/)>9/.-(*/<<'$'),(+$8>$%=(&8=+8)'),.(?4(&%.'" JD" I.'(&(%(/).,'%*(8<(4+5(;-')(,$%).<8$=/)>(%(5/.,(/)(+5%&'" !##$ L11.;(*+'(&3-'(6)1'53-'(*.(D'(&B'<)6)'/(6.,(D.*+()5B0*(35/(.0*B0*$ ">?$ I*35/3,/)V'(C.0,(*'&*&(;)*+(3'<7##/%91&'(.,(3'<7##M8-'$ !JJ$ Q+','(B,'6)A(/','6','5<)54()&(0539.)/3D1':(B0*(D,3<'&(3,.05/(*+'( !6O" W%:'(5/.,N$',9$)/)>(.9?$89,/)'.($',9$)(,-'(E8?C/89.B(C%59'(/)(.&%5%$( I*35/3,/)V'(C.0,(*'&*(&0)*'&(;)*+(3'<7##R:-6'<<$ 6M" T??$(/*'),.(?4(+$'<G" JF" I.'(%(.9?$89,/)'(&%55(,8(<%&,8$(89,(&8=+5'G(5/.,(,$%).<8$=%,/8)." !#7$ I*35/3,/)V'(.5(3(&)541'(3BB,.3<+(*.(<.--35/21)5'(B,.<'&&)54$ ">!$ ,'6','5<'$ &8),'G," @O" T??$'C/%,'(8)54(;-')(,-'(='%)/)>($'=%/).(9)%=?/>989." JH" R'C'$(=8*/<4(()(/)(%(5/.,(<9)&,/8)" !7?$ 5&0,'(*+3*(C.0,()5*',63<':(,052*)-'(-'&&34'&:(35/(/.<0-'5*3*).5( ">"$ Q,)*'(*'&*(<3&'&(*+3*(63)1$ !JK$ 8'9',(0&'(&C-D.1)<(,'6','5<'&$ !6!" Y-')(,-'$'(/.()8(E8?C/89.B(.&%5%$(&8),'G,($',9$)(C%59'Q(&8)./*'$( @!" TC8/*(9./)>(/)-'$'),54(%=?/>989.(;8$*.(/)()%='." JJ" TC8/*(&%.&%*/)>(%)(1&" ,'-3)5(<.5&)&*'5*$ ">>$ U'&*(D.*+(*+'(1)='1C(35/(*+'(051)='1C$ !JM$ %&'(+#/0#$(*.(B,'9'5*(<),<013,(/3*3(&*,0<*0,'&(6,.-(1'3=)54(-'-.,C$ /3;-+,-<6=..>+-<4;(/).,'%*" @6" K$'</G(E<8$(/),'$)%5(9.'(8)54B(.9?$89,/)'.(;/,-(%)(9)*'$.&8$'" JL" I.'(,%?5'(588:N9+(/)(+$'<'$')&'(,8(&%.&%*'*('Z9%5/,4(,'.,." !7!$ W3<*.,(.0*(<.--.5(<.--35/21)5'()5*',63<'(<.-B.5'5*&()5*.(3( ">J$ L//(5';(*'&*(<3&'&(D'6.,'(C.0(&*3,*(/'D044)54$ JM" Y-')(+$8*9&/)>(%(C%59'Q(9.'(,%?95%$(,'$)%$/'." !66" A8)B,(9.'(.9?$89,/)'(+$8,8,4+'." &+3,'/(-./01'$ ">K$ L1;3C&(4'#5'*()%*$ Values and Expressions RegularA8)B,(9.'(6(]321"!(588+." LO" Expressions !6@" T5;%4.($',9$)(C/%(%)('G+5/&/,(%!*-%)" ">M$ L1;3C&(*0,5(.5(;3,5)54&('AB1)<)*1C$ !6D" I.'(%(?%$'(%!*-%)(,8($',9$)(<%/59$'" ">N$ 8'9',(3&&0-'(*+3*(3(;3,5)5426,''(<.-B)13*).5()-B1)'&(<.,,'<*5'&&$ L!" 3'^'&,(%.(=%)4(/,'$%,/8).(%.(+8../?5'Q(%.('%$54(%.(+8../?5'" !JN$ L1;3C&(0&'(*+'(=>(6134$ @@" I.'(/),'$+85%,/)>(.,$/)>(*'5/=/,'$.(8)54(<8$(.,$/)>.(,-%,(%&,9%554(/),'$N L1;3C&(0&'(*+'(=9(6134$ Objects ">#$ U0,5(.66(&*,)<*0,'&(.,(;3,5)54&('AB1)<)*1C:(&'1'<*)9'1C:(35/()5(*+'( !J#$ L6" A8)B,(&8),8$,(588+(.,$9&,9$'.(^9.,(,8(&8).85/*%,'(&8),$85" +85%,'" @D" A8)B,(9.'(!!(8$(""(<8$(%)('=+,4(.,$/)>" L@" I.'(&(%(%)*(%!6((/).,'%*(8<(%)(/$$'>95%$54(&89),'*(321"!" !J7$ %&'(?@(35/(?A(3&(&*,)54(D.05/3,C(35<+.,&$ I/O !7"$ X3='(.D['<*(.,)'5*3*).5(3(<+.)<':(5.*(3(/'6301*$ &-311'&*(B.&&)D1'(&<.B'$ LD" X%?'5('C'$4(588+(,-%,(/.('G/,'*('G+5/&/,54Q(%)*(9.'(,-'(5%?'5(;/,-(!7>$ @+..&'(.D['<*(.,)'5*3*).5(0&)54(3BB,.B,)3*'(<,)*',)3$ !K?$ %&'(?A:(5.*(?B:(*.()5/)<3*'(R'5/(.6(&*,)54P$ ">7$ _'3,5(3*(1'3&*(3(&0D&'*(.6(*+'(B',1(/'D044',$ @F" A8)B,(;$/,'(8)'N&-%$%&,'$(.,$/)>.(/)(C/.9%554(%=?/>989.(;%4." !K!$ L1;3C&(0&'(*+'(=<(6134$ !6F" A8)B,(9.'(?%$';8$*(</5'-%)*5'." !7J$ O.5P*(0&'(B&'0/.+3&+'&$ "J?$ %&'(&',)31)V'/(;3,5)54&(;+'5(/'D044)54(R-350311CP$ 'C'$4()!7*Q("+#*Q(8$(%!6(" !6H" I.'(/)*/$'&,(</5'-%)*5'." @H" I.'()%='*(&-%$%&,'$('.&%+'.(/).,'%*(8<()9='$/&('.&%+'." !K"$ @.5&)/',(-35/3*)54(*+'(C'D'>1##@078E&:D<(-./01'$ !7K$ O.5P*(0&'(,'&*,)<*'/(+3&+'&$ "J!$ @.5&)/',(0&)54(R&-3,*(<.--'5*&P(;+'5(/'D044)54:(,3*+',(*+35( @J" I.'()%='*(&8).,%),.Q(?9,(*8)B,(9.'('()#*+)*" !6J" P<(489(-%C'(,8(9.'(%(+%&:%>'(</5'-%)*5'Q("('+"/0'(/,(</$.," !7M$ L1;3C&(0&'(6011C('5<3B&013*'/(.D['<*&$ +/($(&*3*'-'5*&$ !K>$ %&'(9FSG()5(B,'6','5<'(*.(=S=()5(-01*)1)5'(,'4'A'&$ @L" A8)B,(+%*(*'&/=%5()9=?'$.(;/,-(5'%*/)>(0'$8." !KJ$ O.5P*(0&'(35C(/'1)-)*',&(.*+',(*+35(=S=(.,(9FSG$ !7N$ ])9'('9',C(<.5&*,0<*.,(*+'(&3-'(&*35/3,/(53-'$ !KK$ E,'6',(&)54013,(<+3,3<*',(<13&&'&(*.('&<3B'/(-'*3<+3,3<*',&$ !7#$ O.5P*(1'*(3(<.5&*,0<*.,(<1.5'(.D['<*&$ !77$ L1;3C&(B,.9)/'(3(/'&*,0<*.,(6.,('9',C()5&)/'2.0*(<13&&$ Miscellanea !KM$ E,'6',(53-'/(<+3,3<*',&(*.('&<3B'/(-'*3<+3,3<*',&$ "??$ Q+'5(<,'3*)54(-'*+./&:(6.11.;(*+'(4'5',31(40)/'1)5'&(6.,(&0D,.02 "J"$ %&'(3(,'9)&).5(<.5*,.1(&C&*'-$ !KN$ E,'6',(B,.B',*)'&(*.('50-',3*'/(<+3,3<*',(<13&&'&$ *)5'&$ "J>$ F5*'4,3*'(5.52E',1(<./'()5*.(C.0,(3BB1)<3*).5&(9)3(*+'(!6&%6'##S !K#$ @.5&)/',(-3*<+)54(3,D)*,3,C(;+)*'&B3<':(,3*+',(*+35(&B'<)6)<(;+)*'&2 "?!$ E,.9)/'(&'B3,3*'(,'3/(35/(;,)*'(3<<'&&.,&$ -./01'&$ B3<'(<+3,3<*',&$ "?"$ O.5P*(0&'(19310'(3<<'&&.,&$ "JJ$ `''B(C.0,(<.56)40,3*).5(1354034'(05<.-B1)<3*'/$ !K7$ T'(&B'<)6)<(;+'5(-3*<+)54(R3&(-0<+(3&(B.&&)D1'P$ !M?$ %&'(<3B*0,)54(B3,'5*+'&'&(.51C(;+'5(C.0()5*'5/(*.(<3B*0,'$ "?>$ O.5P*(0&'(*+'()5/),'<*(.D['<*(&C5*3A$ "JK$ O.5P*(0&'(-!(3/*&$ !M!$ %&'(*+'(50-',)<(<3B*0,'(93,)3D1'&(.51C(;+'5(C.0P,'(&0,'(*+3*(*+'( "?J$ E,.9)/'(35(.B*)-31()5*',63<':(,3*+',(*+35(3(-)5)-31(.5'$ "JM$ O.5P*(*)#(93,)3D1'&(.,(6)1'+35/1'&$ B,'<'/)54(-3*<+(&0<<''/'/$ "?K$ H9',1.3/(.51C(*+'()&.-.,B+)<(.B',3*.,&(.6(314'D,3)<(<13&&'&$ "JN$ O.5P*(D'(<1'9',$ !M"$ L1;3C&(4)9'(<3B*0,'/(&0D&*,)54&(B,.B',(53-'&$ "?M$ L1;3C&(<.5&)/',(.9',1.3/)54(*+'(D..1'35:(50-',)<:(35/(&*,)54(<.',2 "J#$ F6(C.0(-0&*(,'1C(.5(<1'9',5'&&:('5<3B&013*'()*$ !M>$ U.='5)V'()5B0*(0&)54(*+'(=DH(6134$ <).5&(.6(.D['<*&$ "J7$ O.5P*(.B*)-)V'(<./'(a(D'5<+-3,=()*$ !MJ$ T0)1/(,'4013,('AB,'&&).5&(6,.-(*3D1'&$ "K?$ O.5P*(.B*)-)V'(/3*3(&*,0<*0,'&(a(-'3&0,'(*+'-$ !MK$ T0)1/(<.-B1'A(,'4013,('AB,'&&).5&(6,.-(&)-B1',(B)'<'&$ Class Hierarchies "K!$ _..=(6.,(.BB.,*05)*)'&(*.(0&'(<3<+'&$ "K"$ L0*.-3*'(C.0,(&0D,.0*)5'(<3<+)54$ !MM$ @.5&)/',(0&)54(C'D'>1##;89986()5&*'3/(.6(;,)*)54(C.0,(.;5( "?N$ O.5P*(-35)B013*'(*+'(1)&*(.6(D3&'(<13&&'&(/),'<*1C$ "K>$ T'5<+-3,=(35C(<3<+)54(&*,3*'4C(C.0(0&'$ ,'4'A'&$ "?#$ %&'(/)&*,)D0*'/('5<3B&013*'/(.D['<*&$ "KJ$ O.5P*(.B*)-)V'(3BB1)<3*).5&(a(B,.6)1'(*+'-$ !MN$ L1;3C&(0&'(<+3,3<*',(<13&&'&()5&*'3/(.6(&)541'2<+3,3<*',(31*',53*).5&$ "?7$ 8'9',(0&'(*+'(.5'23,40-'5*(6.,-(.6(D1'&&$ "KK$ T'(<3,'601(*.(B,'&',9'(&'-35*)<&(;+'5(,'63<*.,)54(&C5*3A$ !M#$ W3<*.,(.0*(<.--.5(366)A'&(6,.-(31*',53*).5&$ "!?$ E3&&(<.5&*,0<*.,(3,40-'5*&(3&(13D'1'/(9310'&:(0&)54(3(+3&+(,'6',2 !M7$ E,'9'5*(0&'1'&&(D3<=*,3<=)54$ '5<'$ !"#$%&"'(%!#)*(+*"'%,"-"#".*"%/0+1"%2"#'+3.%45645665 !N?$ E,'6',(6)A'/2&*,)54(#1(<.-B3,)&.5&(*.(6)A'/2B3**',5(,'4'A(-3*<+'&$ "!!$ O)&*)540)&+(3,40-'5*&(6.,(D3&'(<13&&'&(DC(<13&&(53-'(3&(;'11$ !"#$%&"'(%!#)*(+*"'%78%,)-+).%/0.1)2 "!"$ I'B3,3*'(C.0,(<.5&*,0<*).5:()5)*)31)V3*).5:(35/(/'&*,0<*).5(B,.<'&&'&$ 9%:66;%<=,"+$$8%>"1+)%?.*5@%A$$%#+BC('%#"'"#2"15 Error Handling "!>$ T0)1/(*+'(&*35/3,/(<13&&()56,3&*,0<*0,'(30*.-3*)<311C$ 3"4"#".*"%56+7"%78%809).%:#0-).' !N!$ U+,.;('A<'B*).5&()5&*'3/(.6(,'*0,5)54(&B'<)31(9310'&(.,(&'**)54(6134&$ "!J$ %&'(;&:<<##/7I(*.(30*.-3*'(*+'(/'311.<3*).5(.6(3**,)D0*'(/3*3$ 9%:66D%EF0+##"$%G3.'0$().*8@%A$$%#+BC('%#"'"#2"15
  • 127.
    • Perl::Tidy -“Parses and beautifies perl source” • Perl::Critic - “Critique Perl source code for best-practices”
  • 128.
    Perl::Tidy use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 129.
    Perl::Tidy use strict; my @list= ( 'Emacs', 'Vi ' ); my $rand = rand(); print "10 random users said:n"; foreach ( 0 .. 10 ) { my $i = int( $rand + rand() ); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 130.
    Perl::Tidy • configurable (parametersor .perltidyrc) • integrates with most text editors • some people use it as an svn hook
  • 131.
    Perl::Critic use strict; my @list=('Emacs','Vi '); my $rand = rand(); print "10 random users said:n"; foreach(0..10) { my $i=int ($rand+rand()); print " $list[$i] users are from Venus" . ", " . "$list[1-$i] users are from Mars" . "n"; }
  • 132.
    Perl::Critic Loop iterator isnot lexical at line 5, column 1. See page 108 of PBP. (Severity: 5)
  • 133.
    Perl::Critic • configurable (severalseverity levels, extendable, .perlcriticrc) • integrates with most text editors • some people also use it as an svn hook • if you don’t own PBP, there’s also user- contributed documentation on each subject
  • 134.
  • 135.
    Further documentation • http://127h.sl.pt- An Introduction to Perl Critic, by Josh McAdams • http://127i.sl.pt - Perl Tidy Perl Critic, by olegmmiller • http://127w.sl.pt - Perl Best Practices Reference Guide

Editor's Notes

  • #32 let&amp;#x2019;s put one statement per line