Listing 1: A Perl program to retrieve the contents of our telephone directory.

#!/usr/bin/perl -w

use strict;
use diagnostics;
use Mysql;

# Connect via Unix sockets to the database on this
# server
my $dbh = Mysql->connect;

# Choose a database

# Send our query, and get a statement handle in
# return
my $sth = $dbh->query(
   "select name,telephone from phone_book");

# Iterate through the returned rows
my @arr = ();

while (@arr = $sth->fetchrow)
    print join("\t", @arr), "\n";