#!/usr/local/bin/perl

open (LIST, "pho-list.txt");
open (BASE, ">database.tab");
$all = "\t";
while (<LIST>) {
	/^(\w+)/;
	$current = $1;
	unless ($all =~ /\t$current\t/) {
		$all = "$all$current\t";
		open (CANTON, "database.tab.bak");
		while (<CANTON>) {
			if (/\t$current$/) {
				/^([^\t]*)\t([^\t]*)\t([^\t]*\t[^\t]*\t[^\t]*)\t([^\t]*)\n$/;
			        $ch = $1;
				$in = $2;
				$f1f2te = $3;
			        $pho = $4;
				if ($in =~ /(\w+)(\d)/) {
					$in = $1;
				}
				print BASE "$ch\t$in\t$f1f2te\t$pho\n";
			}
		}
		close (CANTON);
	}
}
close (LIST);
close (BASE);
