){
next if $. == 1;
chop;
$t{NO}++;
$t{TYPE1} = 0;
@fld = split($t{d1});
$t{A1} = $fld[0];
if ( $t{A1} =~ /[A-Z]/ ) {
$t{A1} =~ s/\s$//g; # 把末尾的空格去掉
$t{LINE_A1}{$t{NO}} = $t{A1};
$t{TYPE1} = 'A1';
$t{A1_old} = $t{A1};
$t{lists}{$t{A2_old}}--; # A1类侵占了A2类的位置,需要减去1
$t{lists}{$t{A3_old}}--; # A1类侵占了A3类的位置,需要减去1
} else {
$t{lists}{$t{A1_old}}++; # A1类自己增加一个空格
}
$t{A2} = $fld[1] + 0;
if ( $t{A2} != 0 ) {
$t{A2} = sprintf("%02d",$t{A2});
$t{LINE_A2}{$t{NO}} = $t{A2};
$t{TYPE1} = 'A2';
$t{A2_old} = $t{A2};
$t{lists}{$t{A3_old}}--; # A2类侵占了A3类的位置,需要减去1
} else {
$t{lists}{$t{A2_old}}++; # A2类自己增加一个空格
}
$t{A3} = $fld[2] + 0;
if ( $t{A3} != 0 ) {
$t{A3} = sprintf("%03d",$t{A3});
$t{LINE_A3}{$t{NO}} = $t{A3};
$t{TYPE1} = 'A3';
$t{A3_old} = $t{A3};
} else {
$t{lists}{$t{A3_old}}++;
}
$t{A4} = $fld[3] + 0;
if ( $t{A4} != 0 ) {
$t{A4} = sprintf("%04d",$fld[3]);
}
$t{LINE_A4}{$t{NO}} = $t{A4};
$t{LINE_B1}{$t{NO}} = $fld[4];
$t{LINE_C1}{$t{NO}} = $fld[5];
if ( $t{TYPE1} ) {
push(@{ $t{LINE_TYPE} },$t{TYPE1});
} else {
push(@{ $t{LINE_TYPE} },'A0');
}
}
close(IN);
# 把数据输出到HTML文件
for $n ( 1 .. $t{NO} ) {
$t{TYPE1} = $t{LINE_TYPE}[$n-1];
if ( $t{TYPE1} eq 'A1' ) {
$t{A1} = $t{LINE_A1}{$n};
$t{A1no} = $t{lists}{$t{A1}} + 1;
# 这个操作是关键! 出了变量$t{LINE_B1}{$n},其他的参数如 td,rowspan等也可以作为Template的变量!
$t{LINE1} = '';
$t{LINE1} .= $t{A1} . ' | ';
$t{LINE1} .= ' | ';
$t{LINE1} .= '' . $t{LINE_B1}{$n} . ' | ';
$t{LINE1} .= '' . $t{LINE_C1}{$n} . ' | ';
} elsif ( $t{TYPE1} eq 'A2' ) {
$t{A2} = $t{LINE_A2}{$n};
$t{A2no} = $t{lists}{$t{A2}} + 1;
$t{LINE1} = '';
$t{LINE1} .= $t{A2} . ' | ';
$t{LINE1} .= ' | ';
$t{LINE1} .= '' . $t{LINE_B1}{$n} . ' | ';
$t{LINE1} .= '' . $t{LINE_C1}{$n} . ' | ';
} elsif ( $t{TYPE1} eq 'A3' ) {
if ( $t{LINE_A4}{$n} == 0 ) {
$t{A3} = $t{LINE_A3}{$n};
$t{A3no} = $t{lists}{$t{A3}} + 1;
$t{LINE1} = '';
$t{LINE1} .= $t{A3} . ' | ';
$t{LINE1} .= ' | ';
$t{LINE1} .= '' . $t{LINE_B1}{$n} . ' | ';
$t{LINE1} .= '' . $t{LINE_C1}{$n} . ' | ';
} else {
$t{A3} = $t{LINE_A3}{$n};
$t{A3no} = $t{lists}{$t{A3}} + 1;
$t{LINE1} = '';
$t{LINE1} .= $t{A3} . ' | ';
$t{LINE1} .= '' . $t{LINE_A4}{$n} . ' | ';
$t{LINE1} .= '' . $t{LINE_B1}{$n} . ' | ';
$t{LINE1} .= '' . $t{LINE_C1}{$n} . ' | ';
}
} else {
$t{LINE1} = '' . $t{LINE_A4}{$n} . ' | ';
$t{LINE1} .= '' . $t{LINE_B1}{$n} . ' | ';
$t{LINE1} .= '' . $t{LINE_C1}{$n} . ' | ';
}
my %row = (
LINE1 => $t{LINE1}
);
push(@loop, \%row);
}
# 输出第二个表格
@loop2 = ();
open(IN,"gbt4754_2.txt") or die "Can't open the file gbt4754_2.txt.\n";
while(){
next if $. == 1;
chop;
@fld = split($t{d1});
$t{A} = $fld[0];
$t{B} = $fld[1];
if ( $#fld == 1 ) {
my %row = (
A => $t{A},
B => $t{B}
);
push(@loop2, \%row);
}
}
close(IN);
$template = HTML::Template->new(filename => "gbt4754_0.htm");
$template->param(loop => \@loop);
$template->param(loop2 => \@loop2);
open(OUT,">gbt4754_2002.htm");
print OUT $template->output;
close(OUT);
print "The output file is gbt4754_2002.htm\n";
__END__;