#!/usr/athena/bin/perl

# for each student, find their real name, and generate a random
#  pseudonym.  Output to tab-separated-values file

# usage: students-to-db.perl students-list  > table.tsv

while (<>) {
      chop;
      # get name via hesiod info, name is fifth field
      $password = (split(':',`hesinfo $_ passwd`))[4];
      $uname{$_} = (split(',',$password))[0];
      print STDERR "Error finding name for $_\n" if ($password !~ /,/);
}

foreach $email (sort keys %uname) {
    do {
	$codename = sprintf("%c%c%c%c %d",
			    97+rand(26),  97+rand(26),
			    97+rand(26),  97+rand(26),  rand(9000)+1000);
    } while (defined($codenames{$codename})); #avoid dups

    $codenames{$codename} = $codename;
    print "$email\t$uname{$email}\t$codename\n";
}
