Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

Independent

Perl tutorial

via Independent

Overview

The Perl Maven tutorial will teach you the basics of the Perl programming language. You'll be able to write simple scripts, analyze log files and read and write CSV files. Just to name a few common tasks.

You'll learn how to use CPAN and several specific CPAN modules.

It will be a good foundation for you to build on.

If you are interested in getting updated when new parts are published, please subscribe to the newsletter.

There is also an e-book version of the material available for purchase. In addition to the tutorial, the eBook also includes some material that is only available pro subscribers.

Syllabus

Introduction

  1. Install Perl, print Hello World, Safety net (use strict, use warnings)
  2. #!/usr/bin/perl - the hash-bang line
  3. Editors, IDEs, development environment for Perl
  4. Getting Help
  5. Perl on the command line
  6. Core Perl documentation, CPAN module documentation
  7. POD - Plain Old Documentation
  8. Debugging Perl scripts

Scalars

  1. Common warnings and error messages
  2. Prompt, read from STDIN, read from the keyboard
  3. Automatic string to number conversion
  4. Conditional statements: if
  5. Boolean (true and false) values in Perl
  6. Numerical operators
  7. String operators
  8. undef, the initial value and the defined function
  9. Strings in Perl: quoted, interpolated and escaped
  10. Here documents
  11. Scalar variables
  12. Comparing scalars
  13. String functions: length, lc, uc, index, substr
  14. Number Guessing game (rand, int)
  15. Perl while loop
  16. Scope of variables in Perl
  17. Boolean Short circuit

Files

  1. exit
  2. Standard Output, Standard Error and command line redirection
  3. warn
  4. die
  5. Writing to files
  6. Appending to files
  7. Open and read from files using Perl
  8. Don't open files in the old way
  9. Binary mode - reading and writing binary files
  10. eof, end of file in Perl
  11. tell
  12. seek
  13. truncate
  14. Slurp mode

Lists and Arrays

  1. Perl foreach loop
  2. The for loop in Perl
  3. Lists in Perl
  4. Using Modules
  5. Arrays in Perl
  6. Process command line parameters @ARGV
  7. Process command line parameters using Getopt::Long
  8. Advanced usage of Getopt::Long for accepting command line arguments
  9. split
  10. How to read and process a CSV file? (split, Text::CSV_XS)
  11. join
  12. The year of 19100 (time, localtime, gmtime) and introducing context
  13. Context sensitivity in Perl
  14. Reading from a file in scalar and list context
  15. STDIN in scalar and list context
  16. Sorting arrays in Perl
  17. Sorting mixed strings
  18. Unique values in an array in Perl
  19. Manipulating Perl arrays: shift, unshift, push, pop
  20. Stack
  21. Queue
  22. reverse
  23. The ternary operator
  24. Loop controls: next and last
  25. min, max, sum using List::Util
  26. qw - quote word

Subroutines

  1. Subroutines and Functions in Perl
  2. Passing multiple parameters to a function
  3. Variable number of parameters
  4. Returning a list, returning an array
  5. Recursive subroutines

Hashes

  1. Perl Hashes (dictionary, associative array, look-up table)
  2. Creating hash from an array
  3. Perl hash in scalar and list context
  4. exists hash element
  5. delete hash elements
  6. Sorting a hash
  7. Count word frequency in a text file

Regular Expressions

  1. Introduction to Regular Expressions in Perl
  2. Regex: character classes
  3. Regex: special character classes
  4. Regex: quantifiers
  5. Regex: Greedy and non-greedy match
  6. Regex: Grouping and capturing
  7. Regex: Anchors
  8. Regex options and modifiers
  9. Substitutions (search and replace)
  10. trim - remove leading and trailing spaces
  11. Perl 5 Regex Cheat sheet

Shell related functionality

  1. Perl -X operators
  2. Perl pipes
  3. Unix commands: chmod, chown, cd, mkdir, rmdir, ln, ls
  4. Unix commands: pwd - current working directory
  5. Running external programs using system
  6. Capturning the output of an external program using qx or backticks
  7. Capturing output asynchronously
  8. Capturing both STDOUT and STDERR
  9. Unix commands: rm, mv, cp: How to remove, copy or rename a file with Perl
  10. Windows/DOS commands: del, ren, dir
  11. File globbing (Wildcards)
  12. Directory handles
  13. Traversing directory tree manually with recursion
  14. Traversing directory tree manually using a queue and using find.

CPAN

  1. Download and install Perl (Strawberry Perl or manual compilation)
  2. Download and install Perl using Perlbrew
  3. Locating and evaluating CPAN modules
  4. Downloading and installing Perl Modules from CPAN
  5. How to change @INC to find Perl modules in non-standard locations?
  6. How to change @INC to a relative directory
  7. local::lib

Examples for using Perl

  1. How to replace a string in a file with Perl? (slurp)
  2. Reading Excel files using Perl
  3. Creating Excel files using Perl
  4. Sending e-mail using Perl
  5. CGI scripts with Perl
  6. Parsing XML files
  7. Reading and writing JSON files
  8. Database access using Perl (DBI, DBD::SQLite, MySQL, PostgreSQL, ODBC)
  9. Accessing LDAP using Perl

Common warnings and error messages

  1. Global symbol requires explicit package name ...
  2. .. also explained in Variable declaration in Perl
  3. Use of uninitialized value
  4. Bareword not allowed while "strict subs" in use
  5. Name "main::x" used only once: possible typo at ...
  6. Unknown warnings category
  7. Can't use string (...) as a HASH ref while "strict refs" in use at ... ...
  8. ... explained in Symbolic references in Perl
  9. Can't locate ... in @INC
  10. Scalar found where operator expected
  11. "my" variable masks earlier declaration in same scope
  12. Can't call method ... on unblessed reference
  13. Argument ... isn't numeric in numeric ...
  14. Can't locate object method "..." via package "1" (perhaps you forgot to load "1"?)
  15. Odd number of elements in hash assignment
  16. Possible attempt to separate words with commas
  17. Undefined subroutine ... called
  18. Useless use of hash element in void context
  19. Useless use of private variable in void context
  20. readline() on closed filehandle
  21. Possible precedence issue with control flow operator
  22. Scalar value better written as ...
  23. substr outside of string at ...
  24. Have exceeded the maximum number of attempts (1000) to open temp file/dir
  25. Deep recursion on subroutine
  26. Use of implicit split to @_ is deprecated ...

Extra articles

  1. Multi dimensional arrays
  2. Multi dimensional hashes
  3. Minimal requirement to build a sane CPAN package
  4. Statement modifiers: reversed if statements
  5. autovivification
  6. Formatted printing in Perl using printf and sprintf

From other books

  1. Splice to slice and dice arrays in Perl
  2. How to improve your Perl code

 

Reviews

Start your review of Perl tutorial

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.