#!/usr/bin/perl # enrollment.pl - associate students with classes # Eric Lease Morgan # April 1, 2008 - second investigation # require use MyLibrary::Core; use MyLibrary::Patron; use strict; # define use constant ENROLLMENT => '../etc/enrollment.txt'; use constant INSTANCE => 'your_page'; # configure MyLibrary::Config->instance( INSTANCE ); $| = 1; my $index = 0; open INPUT, " < " . ENROLLMENT or die "Can't open enrollment file ($!)\n"; while ( ) { chop; my ( $code, $subject, $level, $section, $username, $fname, $lname, $rank, $status ) = split /\t/; next if ( $status ne 'Enrolled' ); my $class = "$subject-$level"; if ( MyLibrary::Patron->new( username => $username )) { my $patron = MyLibrary::Patron->new( username => $username ); my $term = MyLibrary::Term->new( name => $class ); $patron->patron_terms( new => [ $term->term_id ]); $patron->commit; print "$index " . $patron->patron_surname . ' (' . $patron->patron_username . ') added to ' . $term->term_name . "\n"; $index++; } else { print "\n$username is not a known patron\n\n"; } } close INPUT;