#!/usr/npac/bin/perl

#/usr/local/bin/perl
$filename2='tqfile.txt.new';
$filename1='entry.list';

open(FILE1,"$filename1");
$n = 0;
while (<FILE1>) {
	$this = $_;
	#print $this;
	if ($this =~ /^"(\d+)","(...)","(\d+)",(.*)$/) {
		#($me,$cat) = split(/","/,$2);
		#$n = length($2);		
		#print "$1 $2\n";
		$table{$1} = $3;
		$n++;
	}
}
#print "\nTotal $n built\n";
close(FILE1);
##############################################
open(FILE2,"$filename2");
$n = 0;
while (<FILE2>) {
	$this = $_;
	if ($this =~ /^"(\d+)","(.*)","(...)",(.*)$/) {
		$tid = $1;
 		$grade = $table{$tid};
		if ($grade ne "") {
			#print "$tid $3\n";
			print "$this\n";
			$table{$tid} = "";
			$n++;
		}
	}
}

#print "\nTotal $n found\n";
# for debug purpose, check missing items in FILE2
#while (($key,$value) = each %table) {
#	if ($value ne "") {
#		print "$key\n";
#	}
#}

close(FILE2);
exit;
