Perl Tutorials - Herong's Tutorial Examples

https://www.herongyang.com/Perl

© 1995-2024 Herong Yang. All rights reserved.

Perl Tutorials 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 introduction of ActivePerl; data types, variables and expressions; scalars, arrays, hash maps, and references; input/output and file systems; DBM files and MySQL access; socket communication; generating executables; XML::Simple and RPC:XML modules; LWP::UserAgent, HTTP::Request and SOAP::Lite modules; CGI, and IIS/Apache integrations. Updated in 2024 (Version v6.02) with minor updates.

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?

Install ActivePerl on Windows Systems

Running Perl Scripts 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

Hard References - Addresses of Memory Objects

Objects (or References) and Classes (or Packages)

Typeglob and Importing Identifiers from Other Packages

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

Image and Picture Processing

Imager - Create and Save Image

Imager - Draw Graphical Elements

Imager - Convert Image File Format

Imager::File::PNG - PNG File Format

Install LIBPNG from Source Code

Install Imager::File::PNG Manually

Install PerlMagick from Source Code

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

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

Converting Perl Script to Executable Binary

Perl Script Conversion Tools

Installing Perl Dev Kit (PDK)

Running PerlApp to Convert *.pl to *.exe

Managing Perl Engine and Modules on macOS

Perl Version Pre-Installed on macOS

Install Xcode Command Line Tools

Configure CPAN Shell

Install Perl Module from CPAN

Install Perl Module from Source Code

Archived Tutorials

Archived: Install ActivePerl v5.18.1 on Windows Systems

Archived: Install ActivePerl v5.8.8 on Windows Systems

References

Full Version in PDF/EPUB

Keywords: Perl, Script, Language, Tutorial, Example