#!/afs/athena/contrib/perl/p

print("What school are you interested in?\n; ");
$sname = (<STDIN>);
chop($sname);
print("What is the persons first name?\n; ");
$fname = (<STDIN>);
chop($fname);
print("What is the persons last name?\n; ");
$lname = (<STDIN>);
chop($lname);


open(FA, "/afs/athena/contrib/consult/doc/college-email-1");&pcef();close(FA);
open(FA, "/afs/athena/contrib/consult/doc/college-email-2");&pcef;close(FA);
open(FA, "/afs/athena/contrib/consult/doc/college-email-3");&pcef;close(FA);

sub pcef {
    while(<FA>){
	$in_it = 1 if /;.*Database.*/;
	next unless $in_it;
	
	if(substr($_, 0,1) =~ /[A-Za-z]/){
	    if($prevtext){
		$Text{$school}=$prevtext;
		if($school =~ /$sname/i){
#		    print("$school\n$prevtext\n");
		    &best_guess($prevtext);
		}
		$prevtext = '';
		$school = $_;
		$school =~ s/[^\w\s]//g;
	    }
	}
	else{
	    $prevtext .= $_;
	}
    }
}


sub best_guess {
    local($text) = @_;

    @ngs = ($fname, $lname, $fname.".".$lname, substr($fname, 0, 1).$lname);
    

    while($text =~ /[\w\d]+@([\S]+\.edu)/g){
	$site = $1;
	for $guess (@ngs){
	    $out = `finger $guess@$site`;
	    print $out unless ($out =~/no .* user| could not find |\?\?\?|unrecogniz/i);
	}
    }
}

