Absolute Beginner's Introduction to Perl 5 and the Perl Community

Will Willis

will.willis@gmail.com

What is Perl?

Origins

The Perl Philosophy

Why Perl?

Getting Perl

Getting Perl

Getting Perl

Your First Perl Script/Program

Variables

Variables?

while (<>) {
  chomp;
  print join("\t", (split /:/)[0, 2, 1, 5] ), "\n";
}

Special Variables & The Default Variable

Operators and Functions

Arithmetic Operators

Shortcut Operators

String Operators

File Test Operators

Functions

Conditional Constructs

What is Truth?

Comparison Operators

Comparison Examples

Boolean Operators

Control Structures

if

if ... else

if ... elsif ... else

while

until

for - more complex looping

for

foreach

Beaking out of Loops

Subroutines

Subroutine Example

sub yyyymmdd {
    my @a = localtime();
    my $yyyymmdd = sprintf( "%04d%02d%02d", $a[5] + 1900, $a[4] 
      + 1, $a[3] );
    return $yyyymmdd;
}

calling a Subroutine

The last one only works if the sub has been predeclared.

Subroutine Arguments

Regular Expressions

The Match Operator

Matching Example

while(){
    print if /foo/;
    print if /bar/i;
    print if m|http://|;
}

Substitutions

Substitution Example

while(){
    s/teh/the/gi;
    s/freind/friend/gi;
    s/sholud/should/gi;
    print;
}

Binding Operator

Metacharacters

Matching something other than literal text

More Metacharacters

Metacharacter examples

while () { 
  print if m|^http|; 
  print if /\bperl\b/; 
  print if /\S/; 
  print if /\$\d\.\d\d/; 
}

Quantifiers

Specify the number of occurrences

Quantifier examples

while () { 
  print if /so+n/;
  print if /\d*\.\d+/;
  print if /\bA\w{3}\b/;
}

Getting Help

  1. Asking Questions the Smart Way
    http://catb.org/~esr/faqs/smart-questions.html

What Next

Acknowledgement