# 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"; } }