1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#!/usr/bin/perl -w
#use strict;
use DBI ;
my $user = "josh" ;
my $passwd = "" ;
my $pdbh = DBI->connect("dbi:Pg:dbname=contacts host=127.0.0.1 port=5432", $user, $passwd);
$action = $pdbh->prepare("SELECT name, pgemail, office_phone, cell_phone, xtra_line, UPPER(continent) as con, region,
url FROM contacts WHERE verified ORDER BY continent, region, name;") ;
$action->execute() ;
$action->bind_columns( undef, \$name, \$pgemail, \$office, \$cell, \$xtra, \$continent, \$region, \$url );
open (CONTACTS, ">", $ARGV[0]) ;
print CONTACTS "List As Of: ". `date`;
my $last_region;
my $last_continent;
while ( $action->fetch ) {
if ( $continent ne $last_continent ) {
print CONTACTS "\n$continent\n";
$last_continent = $continent;
}
if ( $region ne $last_region ) {
print CONTACTS "$region\n";
$last_region = $region;
}
print CONTACTS "$name\n";
print CONTACTS "$pgemail\n";
$office and print CONTACTS "Phone: $office\n";
$cell and print CONTACTS "Cell: $cell\n";
$url and print CONTACTS "$url\n";
$xtra and print CONTACTS "$xtra\n";
print CONTACTS "\n";
}
$pdbh->disconnect;
close CONTACTS;
exit(0);
|