book musings



missle defense



cultcha blog


scripts & programs

on the town



creds (PDF)



Perl Snippets

Below are a set of simple programs that demonstrate some basic functionality of the Perl programming language. Each program provides a simple example of how a single feature of Perl works.

Each program can either be scanned or actually run. Click on the link to look at the program. To run one, download the file, make it executable for your own machine (Change the permissions so you can execute it, and, if it's Windows or some non-Linux operating system, change the path in the first line to where your copy of Perl is).

Keep in mind, nothing much happens when you actually run one of these programs. Mostly, they print out poetry. The idea is that if you want to tinker with the program itself, to explore how each feature works, then you have a working program to start with.

Input: (Program), (Text File)

ARGV Input: (Program), (Text File)

Reading a File: (Program), (Text File)

File Handles: (Program), (Text File) (Sample File)

User-Supplied File Name: (Program), (Text File)

ForEach Loop: (Program), (Text File)

IfElse Loop: (Program), (Text File)

While Loop: (Program), (Text File)

Array Basics: (Program), (Text File)

Subroutines: (Program), (Text File)

Passing An Array To A Subroutine: (Program), (Text File)

Multidimensional Array Sort: (Program), (Text File)

Hashes: (Program), (Text File)

Regular Expressions: (Program), (Text File)

Reverse Operator: (Program), (Text File)

Formatting: (Program), (Text File)

Reverse Operators: (Program), (Text File)

Date Parsing: (Program), (Text File)

Converting a Timestamp: (Program), (Text File)

Connecting To A Database and Running a SQL query: (Program), (Text File)

Saving the results of a SQL query in an array: (Program), (Text File)

Extracting substrings: (Program), (Text File)

Perl Programs

Create a Directory Listing in HTML: A Perl program that makes a bare-bones HTML file listing all the files in a directory. First it asks you the name of the directory to index, then it asks for the name of the file it will create to store the directory info: (program) (source code)

iTunes Music Parser: This Perl program scans an iTunes music library XML file and returns to the screen an HTML listing of the last date each song was played, in chronological order (see sample). You can set the specific years you want it to list.

Database Music Parser: This Perl program enters selected music library information into a MySQL database, taking data from the iTunes music library XML file.

Perl Resources

Perl Delicious Links