Perl 5 Basic

מק"ט: #42600 | משך קורס: 40 שעות אק'

This is an introduction to the Perl language yet covers enough to be able to produce useful programs and to maintain basic scripts.
This course is suitable for programmers and system administrators seeking to write fast, powerful and efficient report generating programs to manipulate data files and logs, or who need a more powerful language to extend shell scripts.  Programmers and analysts intending to implement Perl programs, e.g. HTML generation, application control, and report generation will find it a suitable first step.
The course environment enables delegates to use either Windows or Linux – or even both if they wish to make comparisons.

הקורס פעיל לקבוצות מטעם ארגונים בלבד, ניתן לשלוח פנייה רק אם מדובר בקבוצה
*שדות חובה
PDF version

מטרות

  • Write and run a Perl 5 script
  • Understand Perl 5 language elements
  • Recognize simple and complex variable types and select appropriately
  • Use Perl 5 operators and built-in functions
  • Understand procedural flow control in Perl 5
  • Program basic input/output
  • Run and control other programs from Perl
  • Write powerful report generating programmes implementing Regular Expressions
  • Take advantage of the vast library of Perl 5 modules and subroutines
  • Develop Perl programs containing advanced Perl constructs
  • Implement advanced data stream handling
  • Implement subroutines and modules
  • Act on Perl run-time warnings and errors, using exception handling
  • Perform pattern matching using advanced Regular Expressions

קהל יעד

This course is suitable for programmers and system administrators seeking to write fast, powerful and efficient report generating programs to manipulate data files and logs, or who need a more powerful language to extend shell scripts.  Programmers and analysts intending to implement Perl programs

תנאי קדם

Students should be familiar with at least one programming language: UNIX shell scripting background is sufficient.   No previous knowledge of Perl is assumed.

נושאים

Part I – Basic

Chapter 1: Language Basics

  • Course objectives
  • Perl documentation
  • Perl history
  • Perl availability
  • Perl popularity
  • Interpreter environment
  • Running a perl script
  • Anatomy of a perl script
  • Controlling the interpreter
  • General Perl syntax
  • A look ahead

 

Chapter 2: Fundamental Variables

  • Variable types
  • Variable definitions
  • About scalars
  • Defined and undefined scalars
  • Scalar literals
  • Arrays and hashes introduced
  • Variable interpolation
  • Predefined variables
  • Some useful literal constants

 

Chapter 3: Arrays and Hashes

  • About arrays
  • Array constructors
  • Array constructors
  • $#array magic
  • Array slices
  • About hashes
  • Hash literals
  • Hash slices

 

Chapter 4: Expressions and Operators

  • Perl operators
  • Numeric scalar operators
  • Precedence and associativity
  • String scalar operators
  • Compound assignment operators
  • Increment and decrement operators
  • Comma operator
  • Assignment in list context
  • Context and type conversions

 

Chapter 5: Scalar Functions

  • Numeric functions
  • The magic variable $_(1)
  • String functions
  • String functions: index
  • String functions: substr
  • Assigning to substrings
  • String functions: split
  • String functions: join

 

Chapter 6: Decision Making in Perl

  • Basic conditional statements
  • Boolean and logical operators
  • What is truth?
  • Short-cuts for the lazy
  • File condition functions
  • Loops
  • foreach
  • The BLOCK
  • Lexical variables – reminder
  • Unconditional flow control

 

Chapter 7: Array and Hash Functions

  • Array and list functions
  • Array functions: shift
  • Array functions: pop
  • Array functions: unshift
  • Array functions: push
  • Array functions: splice
  • List functions: reverse, sort, grep, map
  • Hash functions
  • Hash examples
  • undef and exists
  • defined vs. exists
  • Deleting hash elements

 

Chapter 8: Input and Output

  • The basics
  • File handles
  • Default file handles
  • New file handles
  • Reading files
  • The magic variable $_(2)
  • Writing files
  • Formatted output – printf
  • Typical behaviour of filters – ARGV
  • Common input idiom
  • Counting lines and bytes in Files
  • Changing the default output handle

 

Chapter 9: Running Processes

  • Family life
  • Running a process from perl
  • `Back ticks`
  • The system function
  • Creating pipelines
  • Command pipelines
  • Special variables

 

Chapter 10: File System Interaction

  • The filename globbing operator
  • Working with files and directories
  • Working with files and directories
  • Detailed file information
  • Stat conversion
  • Directory information

 

Chapter 11: Regular Expressions

  • Regular expressions
  • Uses of regular expressions
  • Perl regular expressions
  • Perl regular expression patterns
  • Basic pattern match syntax
  • Basic substitution syntax
  • Processing of regular expressions
  • Matching alternatives
  • Anchors
  • Class shortcuts
  • Repeat quantifiers
  • Quantifiers
  • What did we match?
  • What did we match? Sub-patterns
  • More capturing sub-patterns
  • Substitution
  • Substitution with interpolation

 

Chapter 12: Subroutines and Modules

  • Subroutines
  • Subroutine return values
  • Subroutine return values: example
  • Passing subroutine arguments
  • Subroutine arguments
  • Getting at subroutine arguments
  • Lexical variables revisited
  • Find the bugs!
  • Modules
  • The library directories
  • Using subroutines from modules
  • Using subroutines from modules
  • Standard modules

 

Part II – Intermediate Topics

 

Chapter 1: Revision, and the Perl Environment

  • Some short-cut operators
  • Lexical variables (1)
  • Controlling the interpreter – Pragmas
  • Always use strictures
  • Perl 5.10 – use feature
  • Lexical variables (2)
  • Lexical pragmas
  • Perl debugging

 

Chapter 2: Context and Types

  • Reminder: variable definitions
  • Defined and undefined scalars
  • Undefining arrays and hashes
  • Predefined variables
  • Some useful literal constants
  • The DATA file handle
  • Here documents
  • Arrays and lists
  • Comma operator
  • Array slices
  • $#array magic
  • Remember hashes?
  • Hash slices
  • The joy of x
  • Context and type conversions

 

Chapter 3: Further Flow Control

  • Revision – basic conditionals
  • Revision – Boolean and logical operators
  • Revision – what is truth?
  • Smart match operator ~~
  • Smart match operator is smart
  • Short circuit operators
  • Labels and loop jump statements
  • The sad case of switch/case
  • A kind-of case statement
  • Pre-5.8 use of labels and last
  • Switch / case statement (5.8)
  • The given statement – 5.9 or later
  • Loop jump statements: continue
  • Advanced for loops
  • In-line conditional operator
  • Defined-Or Operator // (5.10)
  • File condition functions
  • Evaluating file conditions

 

Chapter 4: References

  • What are references?
  • Uses of references
  • Creating references
  • Using references
  • Dereferencing array and hash references
  • Using references
  • Examining references
  • Complex data structures
  • Data::Dumper
  • Reference counting

 

Chapter 5: Advanced Subroutines

  • Calling a subroutine
  • Subroutine return values
  • Subroutine return values – context
  • Subroutine arguments
  • Named and default parameters
  • Parameter passing – by value?
  • Parameter passing – by reference?
  • Parameter passing – by magic
  • Explicit pass by reference
  • Subroutine prototypes
  • Prototype syntax
  • Prototypes – automatic call by reference
  • References to subroutines
  • Closures
  • Subroutine as an lvalue

 

Chapter 6: Advanced List Functions

  • Sorting
  • Revision – array and list functions
  • List functions: reverse, sort, grep, map
  • The sort function
  • Custom sort order
  • Avoiding sort
  • Sorting hashes
  • map
  • grep

 

Chapter 7: Input and Output

  • File handles
  • New file handles
  • Scalar variables with handles
  • The magic variable $/
  • The ‘flip-flop’ operator
  • Formatted output – printf
  • Changing the default output handle
  • Alternative IO functions
  • File::Find
  • The Perl IO model
  • Using sysopen
  • Reading and writing files
  • Random access

 

Chapter 8: Advanced Regular Expressions

  • Regular Expressions in Perl
  • Review: Perl RE meta-characters
  • Regular expression quoting
  • Modifiers for regular expressions
  • Review of side-effect variables
  • Back-references
  • More capturing groups
  • Non-capturing groups
  • Other capturing variables
  • Named captures (5.10)
  • Minimal matches
  • Multi-line matches
  • Alternatives to ^ and $
  • Global matches
  • Global match progress
  • Comments in Regular Expressions
  • Substitution with interpolation
  • Look-around assertions
  • Substitution using expressions

 

Chapter 9: Modules

  • Splitting into modules
  • Using modules
  • The library directories
  • Using subroutines from modules
  • Writing modules: structure of a module
  • Namespaces
  • Using modules without symbol export
  • Example of unconditional export
  • Example of on-demand export
  • Symbol export using tags
  • BEGIN and END blocks
  • Order of BEGIN and END blocks
  • Attaching a module with require
  • Standard modules
  • Adding modules
  • Other ways of getting modules

 

Chapter 10: Handling Errors and Exceptions

  • Warnings and diagnostics
  • Controlling warnings
  • Error handling
  • Errno module
  • Error handling – Carp
  • Dealing with undef
  • eval
  • eval syntax
  • Error trapping using eval
  • Dying with a reference
  • Signal handling in Perl
  • Alternative signal handling
  • Sending signals
  • Timing out – alarm
  • Fake signals
  • warn and carp
  • Processing the warn and die signals
  • Errors in child processes
תגיות