#!/usr/local/bin/perl use DBI; ### connect to database open(pwfile, "/usr/local/bin/sqlpw.cfg") or die "Cannot open password file"; $pw = ; close(pwfile); chomp $pw; ($machine, $user, $pw, $sid) = split /\//, $pw; $dbh = DBI->connect("DBI:Oracle:host=$machine;sid=$sid", $user, $pw) or die "connecting: $DBI::errstr"; $letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $idx = 0; while ($idx < 26) { $theletter = substr($letters, $idx, 1); $sqlquery = sprintf("select count (*) from wmichdb.patron where last_name like '%s%c'", $theletter, 37); $sth = $dbh->prepare($sqlquery) or die "preparing query statement"; $rc = $sth->execute; $count = $sth->fetchrow_array; printf ("%s: %6.6d\n", $theletter, $count); $idx++; } $sth->finish; $dbh->disconnect;