含兴奋剂目录所列物质的药品一览HTML转换程序

返回


变换程序

use strict; use HTML::Template; use utf8; my(%t,@fld,$n,$template,@loop); print "Please input filename(*.txt)="; chop($t{root}=<STDIN>); $t{inputf} = $t{root} . '.txt'; $t{htm0} = $t{root} . '0.htm'; $t{outputf} = $t{root} . '.htm'; open(IN,"name.txt") or die "Can't open the file name.txt.\n"; while(<IN>) { if ( /^8888/ ) { @fld = split; $t{d1} = $fld[1]; } } close(IN); # Read excel data @loop = (); $t{NO} = 0; open(IN,"$t{inputf}") or die "Can't open the file $t{inputf}.\n"; while(<IN>){ chop; $t{NO}++; @fld = split($t{d1}); $t{TYPE1} = 0; $t{A1} = $fld[0]; if ( $t{A1} ne "\t" ) { $t{TYPE1} = 'A1'; $t{LINE_A1}{$t{NO}} = $fld[0]; $t{LINE_B1}{$t{NO}} = $fld[1]; $t{P1} = 'P' . $t{NO}; $t{lists}{$t{P1}}++; } else { $t{lists}{$t{P1}}++; $t{LINE_B1}{$t{NO}} = $fld[1]; } if ( $t{TYPE1} ) { $t{LINE_TYPE}{$t{NO}} = $t{TYPE1}; } else { $t{LINE_TYPE}{$t{NO}} = 'A0'; } } close(IN); for $n ( 1 .. $t{NO} ) { $t{TYPE1} = $t{LINE_TYPE}{$n}; if ( $t{TYPE1} eq 'A1' ) { $t{A1} = $t{LINE_A1}{$n}; $t{P1} = 'P' . $n; $t{P1no} = $t{lists}{$t{P1}}; $t{LINE1} = '<tr bgcolor="lightcyan"><td rowspan=' . $t{P1no} . '>'; $t{LINE1} .= $t{A1} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_B1}{$n} . '</td></tr>'; } else { $t{LINE1} = '<tr bgcolor="lightcyan">'; $t{LINE1} .= '<td>' . $t{LINE_B1}{$n} . '</td></tr>'; } my %row = ( LINE1 => $t{LINE1} ); push(@loop, \%row); } $template = HTML::Template->new(filename => "$t{htm0}"); $template->param(loop => \@loop); open(OUT,">$t{outputf}"); print OUT $template->output; close(OUT); print "The output file is $t{outputf}\n"; __END__;

样本文件1(f10.htm)

<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>附件1:含兴奋剂目录所列物质的化学药品及生物制品品种名单</TITLE> </HEAD> <BODY bgcolor="#FFFFFF"> <center> <h2>附件1:含兴奋剂目录所列物质的化学药品及生物制品品种名单</h2> </center> <hr color="#003366"> <center> <table width=75% align="center" border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th width=40%>兴奋剂中文名</th> <th width=60%>药品通用名称</th> </tr> <TMPL_LOOP NAME="LOOP"> <TMPL_VAR NAME="LINE1"> </TMPL_LOOP> <tr bgcolor="#3399FF" align="center"> <th width=40%>兴奋剂中文名</th> <th width=60%>药品通用名称</th> </tr> </table> <hr color="#003366"> </center> <a href="index.html">返回</a><br> </BODY> </HTML> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>附件2:含兴奋剂目录所列物质的中药品种名单</TITLE> </HEAD> <BODY bgcolor="#FFFFFF"> <center> <h2>附件2:含兴奋剂目录所列物质的中药品种名单</h2> </center> <hr color="#003366"> <center> <table width=75% align="center" border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th width=40%>兴奋剂中文名</th> <th width=60%>药品通用名称</th> </tr> <TMPL_LOOP NAME="LOOP"> <TMPL_VAR NAME="LINE1"> </TMPL_LOOP> <tr bgcolor="#3399FF" align="center"> <th width=40%>兴奋剂中文名</th> <th width=60%>药品通用名称</th> </tr> </table> <hr color="#003366"> </center> <a href="index.html">返回</a><br> </BODY> </HTML>

样本文件2(f20.htm)

-------------------------------------------
返回