Perl Circus - Three Rings of Perl Tricks.

Usage Notes

The code snippets listed on this site are not guaranteed to be safe for you to run in your environment -- only you can determine that. I've tested each on my own system and found they are suitable for my own purposes. I'm usually running Mac OS X Darwin 10.4.7 and perl 5.8.8 (or later, by the time you read this), but I sometimes use various flavors of Linux and Unix as well. None of these snippets are promised to work on systems that are not Unix-like.

I have assumed that the following four lines will be placed at the top of every executable script file example given on this site even though, for the sake of brevity, it is not always shown.

#!/usr/bin/perl
use strict;
use warnings;
require 5.008_006;

Most importantly, if you are not 100% certain of what a script does or if it is safe to install and run in your particular environment don't. Obviously I can't take any responsibility whatsoever for the damage you will cause by not following that advice.

Which perl?

It might appear that I randomly use the lowercase perl or the uppercase Perl; in fact there is a difference. I use the uppercase version to mean the language of Perl, while the lowercase perl means the executable tool that runs Perl code on your system. More importantly, wherever you see the word perl you should substitute the correct reference to your own perl executable.

If you're not sure, you can learn the correct way to refer to your perl executable by asking your system admin. It's very likely to be /usr/bin/perl or /usr/local/bin/perl, but if your system's PATH variable is configured to include those directories, you should be able to just say perl.

Typographical Conventions

The examples listed on this site are sometimes meant to be entered at a shell command prompt in a terminal window. At other times the code is meant to be saved in a text file. Code that is meant to be entered at a command prompt will always be preceded with a $ shell prompt character, like so...

$ ls -1a | perl -nle 'print if /^\./'

I usually use the bash shell. Depending on what shell you are using, your actual prompt may look different. In any case, when it is used here you should wait for a prompt before typing the given code. Of course, the $ is not part of the code and should not be typed by you.

Ownership

Some of the code samples listed here were not written by me, or were partially written by me, or were modified by me. In some cases they were written entirely by me. I don't claim ownership over any of it. They're too short and basic to be claimed as copyrightable work anyway. Some of it has come from books, others from the perl documentation or public websites and discussion boards. More often than not it's a combination of all of the above.

Occasionally a reader will email me a code snippet, in which case, if it's a good'n', I'll post it with that contributor's name cited at the bottom. I like people who join in.

What I do claim are the explanatory text that goes with each snippet. I work pretty hard at writing concise and understandable text that will hopefully teach a little about the code. Perl Circus has been mirrored and also translated into other languages with my blessing. If you'd like use Perl Circus in a way that involves reproducing the content, you should contact Michael Mathews <micmath@gmail.com> first to obtain permission.