#!/usr/bin/perl -w ### This program deals with an array of records. The records are objects ### of type Student, which are defined in Perl Module called StudentRec.pm require StudentRec; # Allows program to use items defined in Perl Module ### subroutine to print out records in an Array sub print_kids { my $kid; foreach $kid (@person) { PrintRec $kid; # Call method "PrintRec" defined for class Student print "\n"; } } #### Initialize Array of Records #### ## Method "new" creates an object of type Student, and then passes ## parameters onto an initialization routine. One would usually ## initialize from a file rather than direct assignment, however. # This Record is defined in typical order (Name, ID, GPA) $person[0] = new Student( 'Name' => "Bill", 'ID' => "12-345-6", 'GPA' => 3.8); # No fields are defined for this record - Constructor uses defaults $person[1] = new Student; # Fields may be defined in any order since the record is a hash $person[2] = new Student( 'GPA' => 4.0, 'Name' => "Hillary", 'ID' => "98-765-4"); # Print out details print "Before...\n"; print_kids; #### Change things a bit #### # Add new person. Undefined fields take the default values $person[3] = new Student('Name' => "Monica"); # Call Modify method in package $person[0] -> Modify('GPA' => 1.6); # Pass key and value in parm list print "After...\n"; print_kids;