Perl Tutorials

Introduction and Overview
What This Book Is and Is Not
What This Book Is Not
What This Book Will Provide
The Layout of This Book
A CPAN Overview
CPAN History
CPAN Motivation
CPAN Layout
CPAN Sites
Summary
A Perl5 Overview and Tutorial
New Features in Perl5
Usability and Simplicity
Lexical Scoping
References
Data Structures
Modules and Libraries
Reusability
Object-Oriented Capabilities
Extensible and Embeddable
Souped-Up Regular Expressions
Enhanced Safety and Security
Other New Features in Perl5
Summary of the New Perl5 Features
Extended Perl5 Tutorial
References
An In-Depth Look at Perl5 Modules
The Short History of Perl Extensions
Modules and Extensions: Purpose and Design
The Perl5 Module: Form and Function
Listing 2.1. A simple extension module.
Listing 2.2. Using the simple extension module.
Listing 2.3. Using a blessed reference to invoke methods from the Foo module.
Listing 2.4. The Customer module.
Listing 2.5. Using the Customer module.
Object-Oriented Techniques
Listing 2.6. Subclassing the Customer module.
Listing 2.7. Using the MyCust subclass.
Listing 2.8. Overriding Customers methods.
Listing 2.9. Using the overridden method in MyCust.
Listing 2.10. Augmenting base class methods.
Practical Issues for Using Modules: Downloading and Installation
Traps for Perl4 Programmers Migrating to Perl5
Summary
Security on the Web
General Server Security
Server Configuration Options
File Permissions Setup and Monitoring Changes in the System
Data Security
General ConsiderationsGlobal versus Local Configuration of Permissions
Directory Access Configuration
Whos There? Configuring Client IP/Domain Restrictions
Another IP Restriction Mechanism: tcpwrapper
Whos There? User/Group Verification
Changing Passwords from the Web
Monitoring Userids
CGI Security
General Considerations: Dos and Donts
Tools for Executing CGI Safely
The Safe Module
Transaction Security
Simplified PGP Transactions Using the PGP Module
Other Considerations
Dont Run Unnecessary Daemons
Sharing Documents Between Serversftpd and httpd
Running httpd in the chroot(2)Environment
Privacy and Server Logs
Problems with Specific Servers
Monitoring Filesystem Changes,Network Security, and Analyzing Password Security
Further Reading
HTML FormsThe Foundation of an Interactive Web
Text Fields
Text Areas
Password Fields
Radio Buttons
Checkboxes
Hidden Fields
Submit Buttons
Reset Buttons
Image Buttons
Listboxes
Popup Menus
File-Upload Fields
Image Maps
Other Form Elements
Generating HTML On-the-Fly with Perl5
Constructing Headers
Constructing Elements
Listing 4.1. Perl code for customer questionnaire.
Included Files
Listing 4.2. Perl subroutine for including another HTML file.
Listing 4.3. parsessi.pl CGI program for including and parsing a .shtml file.
Closing Up
Heady StuffGenerating More Advanced (Possibly Dynamic) HTML
Other Elements Within Elements
Listing 4.4. Perl code that emits a form formatted using the <TABLE> object.
Other Objects: Applets, Images, Animation, and the <EMBED> Tag
What Forms Cannot Provide
Summary
Putting It All Together
HTTP Transactions
The Connection
The Request
Table 5.1. HTTP FullRequest methods.
Table 5.2. URI Characters That Must Be Encoded.
Table 5.3. Headers.
What Happens after the Request
The Response
Perl5 and the WWW Libraries in Action
CGI.pm versus Individual libwww Modules
URL:
Example 1: Creating Forms with CGI.pm
Listing 5.1. Using CGI.pm with forms
Example 2: Open a New Browser Window
Listing 5.2. Open a new browser window
Example 3: Upload a File to the Server
Listing 5.3. Upload a file to the server
Example 4: Using CGI::Carp to Debug Scripts
Listing 5.4. Using CGI::Carp to debug scripts
Using the HTTP::Request Module Directly
Summary
MIME Documents
MIME, WWW, and CGI
The MIME-Version Header Field
The Content-Type Header Field
The Content-Transfer-Encoding Header Field
Additional Header Fields
How MIME Data Is Encoded
B Base64 Encoding
Q Quoted-Printable Encoding
Encoding and Decoding MIME with libwww
Using MIME::Base64
MIME attachment
Using MIME::QuotedPrint
Simple PleasuresExamples
Guest Book
Determining Fields of Information
Setting Up the Database
Displaying the Form
Listing 7.1. Perl subroutine for printing the guest book form.
Processing the POST
Listing 7.2. Perl subroutine to process the form data.
Putting It All Together
Listing 7.3. Main Perl guest book CGI program.
Displaying the Complete Guest List
Listing 7.4. CGI program to display the guest list.
Review
Hit Counter
Introduction
Setting Up the Web Server to Log Access
Parsing the Access Log
Listing 7.5. Perl subroutine to count the number of hits on a given page.
Listing 7.6. CGI script that displays a graphical hit counter.
Parsing the RefererLog
Parsing the AgentLog
Review
Clickable Maps
Introduction
Creating an Image
Creating the Map
Listing 7.7. Clickable image CGI example.
Review
Text File Search
Introduction
Defining the Search Scope
Listing 7.8. Subroutine to return a search form.
The Power of Perl in Text File Processing
Listing 7.9. Subroutine to search for a list of words.
Displaying the Results
Listing 7.10. A simple CGI searching program.
Review
E-Mail Notification
Introduction
Displaying the Form
Listing 7.11. Subroutine to print a license plate form.
Querying the License Plate Database
Listing 7.12. Subroutine to search for a specific license plate in the database.
Listing 7.13. Subroutine to print the information found about the license plate.
Formatting the Mail Text
Listing 7.14. Subroutine for sending e-mail notification.
Listing 7.15. The license plate notification CGI program.
Review
Summary
Database Access
DBI
Using DBI to Solve a Real World Problem
Listing 8.1. Records to be imported into database
Importing Data into a Database with DBI
Listing 8.2. Program that imports data into an mSQL database
Create an HTML Index from a Database
Listing 8.3. Program that writes HTML from the database
Build HTML from Data on a Single Item in the Database
Listing 8.4. Program that writes HTML from data
about a single item in the database.
Searching the Database for Keywords and Outputting Results
Listing 8.5. Searching the database for keywords
Open Database Connectivity (ODBC)
Summary
AgentsWeb Scanning, Mirroring, and Background Tasks
Retrieving Specific Documents from the Web
Stock Quotes on the Hour
Listing 9.1. HTML returned by the Security APL Quote Server.
Listing 9.2. Automatic stock quote retriever (getquote.pl).
Listing 9.3. Subroutine to extract the quote information.
Adapting the Code for General Purpose Use
Listing 9.4. General purpose URL retriever going through a firewall.
Generating Web Indexes
Web RobotsSpiders
Listing 9.5. The crawlIt() main function of the Web spider.
Listing 9.6. Converting a relative URL to an absolute URL.
Listing 9.7. Writing the title and URL to the log file.
Listing 9.8. Specifying the starting points and stopping points.
Mirroring Remote Sites
Listing 9.9. Modified function to convert relative URLs to absolute URLs.
Listing 9.10. Modified crawlIt() function for mirroring a site.
Summary
Search Engines
On-Site Searching with Glimpse
Glimpse Indexes
GlimpseHTTP
Search the Web with WWW::Search
Listing 10.1. search.PL
a real world example of WWW::Search.
Summary
Datebooks, Calendars, and Scheduling on the Web
HyperCalA Modular Perl5 Calendar and Datebook
Listing 11.1. hypercal.cgi
Configuration of HyperCalThe Variables File
Listing 11.2. Variables and configuration file for HyperCal.
Displaying Appointments on a Specific Day: disp_day.cgi
Listing 11.3. disp_day.cgi.
Adding Calendar Entries with add_date.cgi
Listing 11.4. add_date.cgi.
Changing User Passwords with password.change
Listing 11.5. password.change.
Other Supplementary Programs
Summary
Multimedia
Implementation Issues
GD: Dynamic Images
GD::Image Module
GD::Polygon Module
GD::Font Module
Hangman Using the GD Module
Server Push Animation Techniques
Other Techniques
Embedding AVI, QuickTime, WAV, and GIF89a within HTML
Summary
Shopping Cart Applications
Implementation Issues
Maintaining a Persistent State
Dynamic Generation of Forms
Database Issues
Security
MiniVend Package
Installation and Configuration
Overview of Features
Use and Customization
Setting Up Your Product Catalog
Setting Up Your minivend.cfg File
Setting Up Your Catalog Pages
Listing 13.1. The main catalog page.
Setting Up Your Search Pages
Listing 13.2. The search page.
Listing 13.3. The browse page.
Displaying Search Results
Listing 13.4. The results display page.
Setting Up Your Order Page
Listing 13.5. The order page.
Other Pages to Complete Your Site
Frames
Additional Tools for Administration of Your Site
A Few Words About Security
Summary
Archive and Document Management
General Archive Management Considerations
Planning, Design,and Layout
Revision Control
Summary of Archive Management Issues
Parsing, Converting, Editing, and Verifying HTML with Perl
General Parsing Issues
Listing 14.1. simpleparse.
Listing 14.2. simpleparse-net.
Editing and Verifying HTML
Listing 14.3. relativize.
Parsing HTTP Logfiles
Listing 14.4. GD_Logfile.pm.
Listing 14.5. GD_Logfile.test.
Converting Existing Documentation to HTML
Converting HTML to Other Formats
Making Existing Archives Available via HTTP
Summary
Client-Side Perl
Embedded Perl Interpreter in a
Web Browser

Executing Perl as a Helper Application
Listing 15.1. HelperAppPerl.
PenguinA New Paradigm in Remote Execution
Parsing Netscape History Files
Summary
Advanced CGI/HTML
Sessions
The Need for an Extended Session
Listing 16.1. A very simple calculator
Listing 16.2. A personal notepad.
Listing 16.3. A Web-based command shell.
Warning and Dangers of Multiple Persistent Servers
Embedded ObjectsAn Internet Proposal
Netscape Cookies and Other Netscape Feature Tags
Summary