Perl HTML::Tempalte でテーブル作成

戻る

# make_tables.pl # 07.12.13 use strict; use HTML::Template; my(%t,@fld,$n,$template,@loop); while(<DATA>){ @fld = split; if ( /^TABLE/ ) { $t{table} = 'TABLE' . $fld[1]; $t{htm0} = 'htm' . $fld[2] . '.htm'; $t{htmfile} = $t{table} . '.htm'; } } close(DATA); $template = HTML::Template->new(filename => $t{htm0}); open(IN,"tables.txt") or die "Can't open the file tables.txt.\n"; while(<IN>){ @fld = split; if ( /^$t{table}/ ) { if ( $t{htm0} eq 'htm1.htm' ) { push(@{ $t{name} },$fld[1]); push(@{ $t{in} },$fld[2]); push(@{ $t{len} },$fld[3]); } else { push(@{ $t{name} },$fld[1]); push(@{ $t{in} },$fld[2]); push(@{ $t{out} },$fld[3]); push(@{ $t{len} },$fld[4]); } } } close(IN); @loop = (); for $n ( 0 .. $#{ $t{name} } ) { $t{name1} = $t{name}[$n]; $t{in1} = $t{in}[$n]; $t{out1} = $t{out}[$n]; $t{len1} = $t{len}[$n]; if ( $t{htm0} eq 'htm1.htm' ) { my %row = ( name1 => $t{name1}, in1 => $t{in1}, len1 => $t{len1} ); push(@loop, \%row); } else { my %row = ( name1 => $t{name1}, in1 => $t{in1}, out1 => $t{out1}, len1 => $t{len1} ); push(@loop, \%row); } } $template->param(std_loop => \@loop); open(OUT,">$t{htmfile}"); print OUT $template->output; close(OUT); print "The output file is $t{htmfile}\n"; __DATA__ C-------TABLE------PAT TABLE 62 2 #TABLE 61 2 #TABLE 7 1 #TABLE 8 2 #TABLE 5 2 #TABLE 4 2 #TABLE 3 2 #TABLE 2 1 -------------------------------------------------------------- <HTML> <HEAD> <TITLE></TITLE> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> </HEAD> <BODY bgcolor="#FFFFFF"> <hr color="#003366"> <table width=75% border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th width=40%>喷嘴编号</th> <th width=30%>内径</th> <th width=30%>长度</th> </tr> <TMPL_LOOP NAME="std_loop"> <tr bgcolor="#48D1CC" align="center"> <td><TMPL_VAR NAME="name1"></td> <td><TMPL_VAR NAME="in1"></td> <td><TMPL_VAR NAME="len1"></td> </tr> </TMPL_LOOP> </table> <hr color="#003366"> </BODY> </HTML> -------------------------------------------------------------- <table width=75% border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th width=25%>喷嘴编号</th> <th width=25%>入口</th> <!-- th width=25% 内径 --> <th width=25%>内径</th> <!-- th width=25% 出口 --> <th width=25%>长度</th> </tr> <TMPL_LOOP NAME="std_loop"> <tr bgcolor="#48D1CC" align="center"> <td><TMPL_VAR NAME="name1"></td> <td><TMPL_VAR NAME="in1"></td> <td><TMPL_VAR NAME="out1"></td> <td><TMPL_VAR NAME="len1"></td> </tr> </TMPL_LOOP> </table> -------------------------------------------------------------- 喷嘴编号 内径 长度 TABLE2 JM-18830B 3.2mm 54mm TABLE2 JM-18840B 4.8mm 54mm TABLE2 JM-18850B 6.4mm 54mm TABLE2 JM-18860B 7.9mm 54mm TABLE2 JM-18870B 9.5mm 54mm TABLE2 JM-18880B 11.1mm 54mm TABLE2 JM-18890B 12.7mm 54mm TABLE2 JM-18831B 3.2mm 150mm TABLE2 JM-18841B 4.8mm 150mm TABLE2 JM-18851B 6.4mm 150mm TABLE2 JM-18861B 7.9mm 150mm TABLE2 JM-18871B 9.5mm 150mm TABLE2 JM-18881B 11.1mm 150mm TABLE2 JM-18891B 12.7mm 150mm 喷嘴编号 内径 出口 长度 TABLE3 JM-17840B 4.8mm 7.5mm 54mm TABLE3 JM-17850B 6.4mm 9.5mm 54mm TABLE3 JM-17860B 7.9mm 11.1mm 54mm TABLE3 JM-17870B 9.5mm 12.7mm 54mm TABLE3 JM-17880B 12.7mm 15mm 54mm TABLE3 JM-17841B 4.8mm 7.5mm 150mm TABLE3 JM-17851B 6.4mm 9.5mm 150mm TABLE3 JM-17861B 7.9mm 11.1mm 150mm TABLE3 JM-17871B 9.5mm 12.7mm 150mm TABLE3 JM-17881B 12.7mm 15mm 150mm 喷嘴编号 内径 出口 长度 TABLE4 JM-16830B 4.8mm 9mm 130mm TABLE4 JM-16840B 6.4mm 10.5mm 135mm TABLE4 JM-16850B 7.9mm 12mm 140mm TABLE4 JM-16860B 9.5mm 14mm 165mm TABLE4 JM-16870B 11.1mm 15.5mm 190mm TABLE4 JM-16880B 12.7mm 17mm 215mm 喷嘴编号 内径 出口 长度 TABLE5 JM-15830B 4.8mm 9mm 130mm TABLE5 JM-15840B 6.4mm 10.5mm 135mm TABLE5 JM-15850B 7.9mm 12mm 140mm TABLE5 JM-15860B 9.5mm 14mm 165mm TABLE5 JM-15870B 11.1mm 15.5mm 190mm TABLE5 JM-15880B 12.7mm 17mm 215mm 喷嘴编号 入口 内径 长度 TABLE61 JM-40042B 7mm 3mm 56mm TABLE61 JM-40043B 8mm 4mm 56mm TABLE61 JM-40044B 9mm 5mm 56mm 喷嘴编号 入口 内径 长度 TABLE62 JM-40045B 10mm 6mm 85mm TABLE62 JM-40046B 11mm 7mm 85mm TABLE62 JM-40047B 12mm 8mm 85mm TABLE62 JM-40048B 13mm 9mm 85mm TABLE62 JM-40049B 14mm 10mm 85mm TABLE62 JM-40050B 15mm 11mm 85mm TABLE62 JM-40051B 16mm 12mm 85mm TABLE62 JM-40052B 17mm 13mm 85mm TABLE62 JM-40053B 18mm 14mm 85mm TABLE62 JM-40054B 19mm 15mm 85mm 喷嘴编号 内径 长度 TABLE7 JM-40075B 6mm 40.5mm TABLE7 JM-40077B 8mm 40.5mm TABLE7 JM-40079B 10mm 40.5mm TABLE7 JM-40081B 12mm 40.5mm TABLE7 JM-40083B 14mm 40.5mm 喷嘴编号 内径 出口 长度 TABLE8 HY-40127B 6mm 8mm 100mm TABLE8 JM-40129B 8mm 10mm 100mm TABLE8 JM-40131B 10mm 12mm 100mm TABLE8 JM-40133B 12mm 14mm 100mm TABLE8 JM-40135B 14mm 16mm 100mm --------------------------------------------------------------
戻る