Skip to main content
main-content
Top

About this book

Get started with Perl 5 and learn the important core concepts of Perl programming, such as variables, flow control, expressions, and I/O. Additionally, this book covers pattern matching and shows that Perl is extremely flexible and powerful, and that it isn’t afraid of the cloud. After reading and using this book, you'll be able to start writing your own powerful scripts to solve many web and programming problems.

This is a book for those of us who believed that we didn’t need to learn Perl, and now we know it is more ubiquitous than ever. You’ll see that Perl has evolved into a multipurpose, multiplatform language present absolutely everywhere: heavy-duty web applications, the cloud, systems administration, natural language processing, and financial engineering. This book provides valuable insight into Perl’s role regarding all of these tasks and more giving you a great start in your Perl programming adventure.

What You Will Learn

Perform operations on scalar valuesUse scalar, array, and associative array variablesWork with flow control statements such as if, unless, while, until, for, and foreachRead and write directly to files with file handles Use conditional expressions such as numeric and string comparison, regular expressions, file testing, and Perl statementsFormat output with format statements Search for and replace sub-strings within a string using regular expressionsMaster Perl utilities such as split, join, index and moreControl the file system and processes from within a Perl scriptBuild functions for tasks including handling the scope of variablesImport existing modules into your Perl script

Who This Book Is For

Those who are new to Perl.

Table of Contents

Chapter 1. Origin of Perl

Abstract
Perl was developed in 1987 by Larry Wall. It was created because the tools that were available to Mr. Wall at the time (sed, C, awk, and Bourne shell) didn’t provide the sort of functionality that he required.
William “Bo” Rothwell

Chapter 2. Scalar Variables

Abstract
A numeric literal is simply any kind of valid number. In Perl the following numeric types are supported:
William “Bo” Rothwell

Chapter 3. Array Variables

Abstract
Array variables are used to store lists (groups) of scalar data. The following describes important information about array variables:
William “Bo” Rothwell

Chapter 4. Associative Array Variables

Abstract
Consider the situation in which you are keeping track of dog names in an array: @dogs=qw(Fido Spot Teddy Rex);
William “Bo” Rothwell

Chapter 5. Flow Control

Abstract
Control statements are used to handle conditional statements. A conditional statement is something that returns a value (true or false) based upon the current data available to your program.
William “Bo” Rothwell

Chapter 6. Conditional Expressions

Abstract
The following operators can be used to compare numbers:
William “Bo” Rothwell

Chapter 7. Basic Input and Output

Abstract
There are several methods of reading input that will be discussed in the next two chapters:
William “Bo” Rothwell

Chapter 8. Advanced Input and Output

Abstract
A filehandle is a connection between your script and a “port.” There are four standard filehandles in Perl by default:
William “Bo” Rothwell

Chapter 9. Pattern Matching

Abstract
Operating systems use “wildcards” in order to make referring to filenames easier. The idea of regular expressions (or patterns) in Perl is very much like wildcards...at least conceptually. While wildcards are special characters that refer to filenames, regular expressions are special characters that refer to text within a string.
William “Bo” Rothwell

Chapter 10. Perl Utilities

Abstract
The split statement is useful for breaking up a scalar value based on a particular character (or characters). It will return what is split as a list (array) of scalar values. This list is normally assigned to an array:   DB<1> $str = "Bob:Jones:23423:manager:O3"   DB<2> @fields=split(/:/, $str)   DB<3> for $item (@fields) {print $i++, " $item\n";} 0 Bob 1 Jones 2 23423 3 manager 4 O3
William “Bo” Rothwell

Chapter 11. Filesystem and Process Control

Abstract
Perl provides several built-in statements that allow you to control the filesystem (files and directories) while within Perl. With these statements, you can
William “Bo” Rothwell

Chapter 12. Functions

Abstract
To create a function, use the sub statement: sub total {   print "The total is ", $a ∗ $b + $c ∗ $d, "\n"; }
William “Bo” Rothwell

Chapter 13. Using Modules

Abstract
Perl modules (sometimes called libraries) are files that contain reusable code. These libraries can either be created by you, built-in to Perl, or downloaded from the Internet.
William “Bo” Rothwell

Chapter 14. Debugging Perl

Abstract
The -w switch (option) will tell Perl to look for and report unusual code. This code typically includes a logical (not syntax) error and includes (but not excluded to) the following:
William “Bo” Rothwell
Additional information