This is the Perl DBI code to access PostgreSQL.

#!/usr/bin/perl -w

use strict;
use DBI;

my $host = "roger";
my $user = "cs898n";
my $password = "abc123";
my $dbname = "cs898n";

my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$host", $user,
$password);

$dbh or die "cannot connect to the database:$!\n";

my @tables = $dbh->tables;
print "@tables\n";

my $sth = $dbh->prepare ("select * from friend");
$sth->execute();

# retrieve the result using the fetchrow_arrayref method
while (my $data = $sth->fetchrow_arrayref ()) {
    my ($fname, $lname, $city, $state, $age) = @$data;
    print "First Name: $fname\n";
    print "Last Name: $lname\n";
    print "City: $city\n";
    print "State: $state\n";
    print "Age: $age\n";
    print "\n";
}

$sth->finish ();
$dbh->disconnect;
print "bye\n";