O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Searchable Address Book (address.pl)

Our first script today consists of two parts:

  • A simple address book file, containing names, addresses, and phone numbers

  • A Perl script that prompts you for things to search for, and then prints out any matching addresses

This script makes use of just about everything you've learned so far this week: scalar and hash data, conditionals, loops, input and output, subroutines, local variables, and pattern matching. There's even a function call here and there to make things interesting. And so, without further ado, let's dive in.

How It Works

The address.pl script is called with a single argument: the address file, called address.txt. Call it on the command line as you have other Perl scripts:

% address.pl address.txt ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required