Penn Computing

Penn Computing

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

Service Alerts


November 16, 2014

On November 16, from 4am to 9am: PennCommunity will not be available because of scheduled maintenance. The following PennNames commands rely on PennCommunity and will not be available during this window: add, hold, fullname, generate, regenerate.

PennNames Perl Example

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

#!/bin/perl

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

chomp($pennid=<FILE>);
close (FILE);

$return=`pennnames session`;

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

$sid=$1;

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

#               204 Success   
if $return!=~/^204.*Success\s+\d+\s+\d+\s+(.*)\s+$/ {
  $fullname=$1;
} 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': "
  $fullname=<>;
}

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

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

@goodnames=();
$neednames=1;

foreach (@names) {
  ($code, $name, $conflict) = m/^(\d\d\d).(.*)\s+(!?)$/;
  if ($code eq "203") {             # this name has already been assigned
      @goodnames=(@goodnames, $name);
      $neednames=0;
  } 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

top

Information Systems and Computing
University of Pennsylvania
Comments & Questions


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