Perl Tutorials - Herong's Tutorial Examples - Version 5.30, by Dr. Herong Yang

Perl Tutorials - Herong's Tutorial Examples

http://www.herongyang.com/Perl

Copyright © 1995-2014 by Dr. Herong Yang. All rights reserved.

HerongYang.com This Perl tutorial book is a collection of notes and sample codes written by the author while he was learning Perl language himself. Topics include ActivePerl, data types, subroutines, debug, references, objects, open, binary, file, directory, DBM, MySQL, regular expression, RPC::XML, XML::Simple, SOAP::Lite, socket, CGI, IIS, socket, Windows, Linux.

Table of Contents

About This Book

Perl on Linux Systems

Perl Installation on Linux Systems

Running Perl Scripts on Linux Systems

ActivePerl on Windows Systems

What Is ActivePerl?

Installing ActivePerl v5.18.1 on Windows Systems

Running Perl Scripts on Windows Systems

Installing ActivePerl v5.8.8 on Windows Systems

Data Types: Values and Variables

Scalar Values and List Values

Scalar Value Constructors

Scalar Value Interpretation

List Value Constructors

Variables - Scalar, Array and Hash

Using Scalar Variables

Using Array Variables

Using Hash Variables

"undef" Value and Undefined Variables

Expressions, Operations and Simple Statements

What Is an Expression?

Expression Evaluation Context

Simple Statements and Modifiers

User Defined Subroutines

Declaring and Calling Subroutines

SubParamList.pl - Example on Parameter List

SubParamAlias.pl - Example on Parameters as Alias

SubReturnValue.pl - Example on Return Values

SubCalling.pl - Example on Calling Formats

Perl Built-in Debugger

Commonly Used Debugging Commands

Debugging Tutorial Session

Name Spaces and Perl Module Files

Including Script Codes from Other Files

do() Function - Including Script Files

require() Function - Including Script Files

"package" Statement - Switching Name Space

BEGIN(), CHECK(), INIT() and END() Functions

Defining Your Own Perl Module

CalendarModule.pm - A Sample Perl Module

Symbolic (or Soft) References

Using Symbolic References

$$name - Replacing Identifiers by Scalar Variables

${EXPR} - Replacing Identifiers by Expressions

EXPR->* - The Dereference Operator

$$$name - Nested Symbolic References

Hard References - Addresses of Memory Objects

\* - Creating Hard References

Using Hard References

$$name - Replacing Identifiers by Scalar Variables

${EXPR} - Replacing Identifiers by Expressions

EXPR->* - The Dereference Operator

$$$name - Nested Hard References

\$b-\$a - Using Hard References in Other Operations

Objects (or References) and Classes (or Packages)

Basic Concepts of Classes and Objects

Invoking Package Subroutines as Class Methods

bless() - Converting References to Objects

Invoking Package Subroutines as Object Methods

Class Variables and Object Variables

new() Method - Creating Objects by the Class

CalendarClass.pm - A Perl Class Example

Typeglob and Importing Identifiers from Other Packages

Typeglob, Symbolic Table and Identifier Aliases

Accessing Identifiers from Other Packages as Aliases

Exporting and Importing Package Identifiers

String Built-in Functions and Performance

String Related Built-in Functions

Performance of Perl substr() and index()

Performance of Java substring() and indexOf()

File Handles and Data Input/Output

open() - Opening File Handles for Input and Output

print() - Printing Output to File Handles

<file_handle> - Reading Data from File Handles

Open Files in Binary Mode

binmode() - Opening Files for Binary Input

binmode() - Opening Files for Binary Output

Copy.pl - Copying Binary Files

Bin2Hex.pl - Converting Binary Data to Hex Numbers

Open Directories and Read File Names

opendir() - Open Directory to Read File Names

opendir.pl - Sample Program to Read Directories

DirTree.pl - Displaying the Directory Tree

DirGrep.pl - Searching Text in Directory Files

File System Functions and Operations

Built-in Functions to Work with the File System

File Test Operators

stat() - Returns File Statistics

Converting Perl Script to Executable Binary

Perl Script Conversion Tools

Installing Perl Dev Kit (PDK)

Running PerlApp to Convert *.pl to *.exe

Using DBM Database Files

dbmopen() - Opening DBM Files with Hash Variables

DBM Database Example - English French Dictionary

DBM Database Example - Book Records with Multiple Fields

Using MySQL Database Server

Installing Database Module for MySQL

HelloMySQL.pl - My First Perl Program with MySQL

Socket Communication Over the Internet

What Is Socket Communication?

connect() - Establishing a Socket Communication

ReverseEchoer.pl - A Simple Socket Server Program

SocketClient.pl - A Simple Socket Client Program

gethostbyaddr() - Network Utility Functions

Socket.pm - The Socket Module

XML::Simple Module - XML Parser and Generator

XMLin() and XMLout() Methods

XML Parsing Options

"forcearray" - Forcing Element Contents as Arrays

"suppressempty" - Parsing Empty Elements

"keyattr" - Namings Attributes as Keys

XmlSimpleHash.pl - XML Hash Example

XML Communication Model

XML Messages over Socket Connections

GameServer.pl - XML Communication Server Example

GameClient.pl - XML Communication Client Example

SOAP::Lite - SOAP Server-Client Communication Module

What Is SOAP?

What Is SOAP::Lite?

SOAP::Transport::TCP - SOAP Server with TCP Protocol

SoapTcpClient.pl - SOAP Client Example with TCP Protocol

SOAP::Lite Tracing Functions

SOAP::Transport::HTTP - SOAP Server with HTTP Protocol

Perl Programs as IIS Server CGI Scripts

Configuring IIS 5.0 for Perl Programs

perl.exe vs. perlis.dll

CGI (Common Gateway Interface)

What Is Common Gateway Interface (CGI)?

IIS Environment Variables

QUERY_STRING - CGI Query String

Calculator.pl - CGI Application Example

XML-RPC - Remote Procedure Call with XML and HTTP

What Is XML-RPC?

Defining a Remote Method Call in XML

Sending a Remote Method Call as a HTTP Request

Defining Returning Values of a Remote Method Call

Receiving Returning Values as a HTTP Response

RPC::XML - Perl Implementation of XML-RPC

What Is RPC::XML?

RPC::XML::Server - XML-RPC Server Interface Class

RPC::XML Client and Data Classes

Installing NMake 1.5

Installing RPC::XML Module

RpcXmlServer.pl - RPC::XML Server Sample Program

RpcXmlClient.pl - RPC::XML Client Sample Program

Sending Arrays with Remote Method Calls

Integrating Perl with Apache Web Server

Downloading Apache HTTP Server 2.2.25 for Windows

Installing Apache HTTP Server 2.2.25 on Windows

Publishing HTML Documents as Web Pages

Starting and Stopping Apache Server

Running Perl Scripts in "cgi-bin"

printenv.pl - Testing Perl CGI Environment

500 Internal Server Error

cgi-lib.pl - The Standard Library for CGI Scripts

ReadParse() - Parsing Web Form Input Values

Running Perl Scripts in "htdocs"

CGI.pm Module for Building Web Pages

What Is CGI.pm?

Generating HTML Document with CGI.pm

Retrieving Query Parameters and Headers

Retrieving Environment and Script Information

Redirecting Browser to a URI

"Refresh" http-equiv Meta Tag

What Is CGI::Cookie?

Retrieving and Setting HTTP Cookies

LWP::UserAgent and Web Site Testing

What Is LWP::UserAgent?

What Is HTTP::Response?

What Is HTTP::Request?

LWP-UserAgent-GET.pl - Sending a GET Request

LWP-UserAgent-GET-Redirect.pl - Following HTTP Redirects

http-equiv="Refresh" Meta Tag not Followed

LWP-UserAgent-POST.pl - Posting Form Data

post() Method not Following Redirect Location

LWP-UserAgent-POST-Redirect.pl - Posting with Redirects

What Is HTTP::Cookies?

LWP-UserAgent-Request.pl - GET, POST and Cookies

LWP-UserAgent-Request.pl - Login to facebook.com

HTTP::Cookies save() not Saving Temporary Cookies

LWP-UserAgent-Request-Cookies.pl - Sending Request with Cookies

References

Printable Copy - PDF Version

Keywords: Perl, Script, Language, Tutorial, Example

Table of Contents - Updated in 2014, by Dr. Herong Yang