# need to chomp the file input before testing
$found = 1 if /^$student\t$studentAge$/;
####
my $text = "$student\t $studentAge\n";
my $found = 0;
while (<$fh>) {
$found = 1 if $_ eq $text;
}
####
# Read the file into a hash
#
my %dataFileContains;
open my $fh, 'students.dat' or die "open failed: $!";
my $line;
while ($line = <$fh>) {
chomp $line;
$dataFileContains{$line}++;
}
close $fh;
#
# Read in and test each value, caching those which
# will be output.
#
my @output;
my ( $name, $age );
while ( ($name, $age ) = getStudentData() ) {
my $outLine = "$name\t$age";
push @output, $outLine unless $dataFileContains{$outLine};
}
#
# Output the data.
#
if ( scalar @output ) {
open my $fh, '>>students.dat' or die "open failed: $!";
foreach ( @output ) {
print $fh, "$output\n";
}
}