#!/s/perl/bin/perl

###
### Slurp the local address and telephone numbers from the directory
### LaTeX files 
### $Id: get_local_info.pl,v 1.1 1995/07/19 22:29:55 bates Exp bates $

require 5.000;

$DIR = '/p/stat/Data/admin/';	# Set the directory
$FSEP = "&";			# separate fields by ampersands
$INPUT = $DIR . "fac_demog_orig";

open (INPUT, "< $INPUT") ||
    die "Unable to open input file $INPUT: $!\n";
open(OUTPUT, "> fac_demog") ||
    die "Unable to open fac_demog for output: $!\n";

while (<INPUT>) {
    /(\s*\\\\\s*)$/;
    @F = split(/$FSEP/, $`);
    for (@F) {
	s/^\s+//;
	s/\s+$//;
    }
    ($name, $phone, $office,  $login, $local_ad, $local_phone, $spouse) = @F;
    next unless $name && $login;
    $local_ad =~ s/\\#/#/g;
    $address{$login} = $local_ad if $local_ad;
    $phone{$login} = $local_phone if $local_phone;
    print join("\t", $name, $login, $uid, $office, $phone, $office_2, $office_2_bldg, $office_2_phone, $local_ad, $local_ad_2, $local_city, $local_zip, $local_phone, $spouse), "\n";
}

exit(0);

close(INPUT);

rename("fac_demog", "fac_demog.bak") ||
    die "Unable to rename fac_demog to fac_demog.bak: $!\n";
open(INPUT, "< fac_demog.bak") ||
    die "Unable to open fac_demog.bak for input: $!\n";
open(OUTPUT, "> fac_demog") ||
    die "Unable to open fac_demog for output: $!\n";

$FSEP = "\t";

while (<INPUT>) {
    chop;
    @F = split(/$FSEP/, $_);
    $login = $F[7];
    if ($address{$login}) {
	($address = $address{$login}) =~ /(53[0-9][0-9][0-9])\s*$/;
	$F[19] = $1;
	($address = $`) =~ s/,\s*$//;
	$F[16] = $address;
	$F[18] = 'Madison';
    }
    if ($phone{$login}) {
	$phone{$login} =~ /([0-9\(\)-]+)/;
	$F[20] = $1;
    }
    print OUTPUT join($FSEP, @F), "\n";
}



