#!/s/std/bin/perl

# $Id: csfacultyemail.pl,v 1.14 2008/12/16 21:57:33 koczan Exp $

# csfacultyemail.pl dumps out email addresses for the csfaculty mailing list

use strict;
use warnings;

use DBI;
use CSL::Pg;
use CSL::DBs;

my $dbh = DBI->connect($CSL::DBs::csdb)
  or die "Could not connect to CSDB: $!";
$dbh->do("set search_path to csdb");

# If they gave a file, redirect STDOUT to there.
my $outfile = shift @ARGV;
if ($outfile) {
  open STDOUT, '>', $outfile
    or die "$0: Could not open $outfile for writing: $!";
}

# Header
# no header this time

# get the data now
my $faculty_query = $dbh->prepare("select login from people where faculty =1 and status is null and login is not null order by login");

$faculty_query->execute;
while (my $row = $faculty_query->fetchrow_hashref) {
  print "$row->{login}\n";
}
print "\n";

# Footer
# no footer this time

# clean up
$faculty_query->finish;
$dbh->disconnect;
