|
wl710-ver2.0
Introduction to CGI Scripting with Perl (2 days)
Description
This courseware training guide book will teach you to harness Perl's potential for processing text, searching HTML pages and text files, and more. Perl allows you to write powerful, flexible, platform-independent scripts that run on your server.
Suggested Prerequisites• Advanced HTML: Introduction to Forms & Scripting
Next Course• Advanced Perl: Database-Driven Web Sites
ObjectivesBy the end of the class students will be able to:
• Understand Perl commands and program structure
• Use regular expressions
• Build a searchable site index
• Search a text file
• Edit text dynamically
Course OutlineIntroduction • Your Files for Class
What is a CGI Script, and What is Perl? • What's Special About a cgi-bin Directory?
Perl Syntax • print Statements • Identifying the Perl Interpreter • The Content-type Header • Printing HTML Content • Comments • Exercise 1: Building a Simple Web Page in Perl
Interpreting Variables • Scalar Variables • Form Variables • Exercise 2: Processing a Form
Working with Scalars • Scalars and Arithmetic • Shortcut Operation and Assignment • Autoincrement (++) and Autodecrement (--)
Conditionals • Testing Existence of a Variable • Comparing Values • Combining Multiple Conditions • More Than Just if-else • Pessimistic Tests With unless • Exercise 3: Testing Form Values with Conditionals
Pattern Matching • Case Sensitivity • Testing Environment for Regular Expressions • Some Common Patterns • Exercise 4: Validating Form Data
Pattern Substitution • Remembering Text with Backreferences • Character Translation • Exercise 5: Substitution and Backreferences
Array Variables • Creating an Array • Individual Array Elements • Counting Array Elements • Reading One Array into Several Scalars • Adding Array Elements with push • Removing an Array Element with shift • Exercise 6: Using Basic Arrays
More Array Functions • Reordering Your Array with sort and reverse • Search Your Array with grep • Change Between Array and Scalar with join and split • Exercise 7: Practicing with Array Functions • A Possible Solution to Exercise 7 • Loops • Looping with while and until • Looping with for • Looping with foreach • Exercise 8: Looping Through Your Array
Reading from and Writing to Files • A Simple Demonstration • What These Scripts Have in Common • Adding Text to a File • Reading Lines from a File • Confirm that the File Opened Properly • Using split to Parse Tab-Delimited Text Files • Exercise 9: Writing to a Text File • Exercise 10: Searching in a Text File
Listing Files in a Directory • Filtering File Names with grep
Introducing Subroutines • How to Write Subroutines • Exercise 11: Building and Calling Subroutines
Making Your Subroutine More Reusable • Passing Variables to a Subroutine • Returning Results from a Subroutine • Variable Scope with my and local • Exercise 12: Passing Variables to and from Subroutines
Hash Variables • Looping Through a Hash • Other Hash Manipulations • Environment Variables: a Ready-Made Hash • Another Useful Loop: All Form Variables • Exercise 13: Practicing with Hashes
Sending Email • The Mail:Mailer Module • Exercise 14: Sending an Email Message
|
|
|
|