Penn Computing

Penn Computing

Computing Menu Computing A-Z
Computing Home Information Systems & Computing Penn

Service Alerts

PennNames Perl Example

Here is a sample perl program which uses PennNames C API.


# read PennID from input file
open(FILE, "$file") || die "can't open file";

close (FILE);

$return=`pennnames session`;

$return=~/^201.*(\d+)$/ || die "can't open PennNames session";


#        pennnames fullname  
$return=`pennnames fullname $sid $pennid`;

#               204 Success   
if $return!=~/^204.*Success\s+\d+\s+\d+\s+(.*)\s+$/ {
} else {
  print "$pennid not in PennCommunity database\n";
  print "please enter full name in last,first format\n";
  print "for example, 'Jones Jr,Jack J': "

#                                pennnames generate    []
($return, @names) = split(/\n/, `pennnames generate $sid 10 $pennid $fullname`);

$return=~/^\d\d\d.Success/) || die "can't generate names";


foreach (@names) {
  ($code, $name, $conflict) = m/^(\d\d\d).(.*)\s+(!?)$/;
  if ($code eq "203") {             # this name has already been assigned
      @goodnames=(@goodnames, $name);
  } elsif ($code eq "202") {        # this name was generated
    # only offer generated names if no usable registered names exist
    if ($neednames) { 
      @goodnames=(@goodnames, $name);
  # ignores codes other than 203 and 202, but checks first line for error

print "Choose one of these:\n";

foreach (@goodnames) {
  print $_, "\n";

print "Which one do you want? ";  $name=<>;

#        pennnames add   
$return=`pennnames add $sid $name $pennid`;

$return=~/^201/ || die "Couldn't register name';

# "add" command terminates session, no "quit" necessary


Information Systems and Computing
University of Pennsylvania
Comments & Questions

Penn Computing University of Pennsylvania
Information Systems and Computing, University of Pennsylvania