While this isn't a book about Perl, you should at least be familiar with how Perl works. So, let's go through the different sections of the presidents.pl program and describe what they do:
-
#!/usr/bin/perl
This specifies the path to the Perl program on the computer.
-
use DBI;
use strict;
The use DBI line means use DataBase Interface. It refers to the Perl module that interacts with your MySQL database. You might think of this module as a MySQL client that speaks Perl. It does most of the things the MySQL client does, but through Perl.
The use strict line is a matter of personal preference and programming etiquette. Variables are "containers" in a Perl script that hold specific information. In Perl, using the strict mode requires you to reserve all variables before they are used. The next bullet shows how this works.
-
# database information
my $db="us_presidents";
my $host="localhost";
my $port="3306";
my $userid="marty";
my $passwd="watch4keys";
my $connectionInfo=
"DBI:mysql:database=$db;$host:$port";
Like the comment says (what comes after a # character is a comment—a note in the program to be read by people, not the computer), this is information about the database.