Perl HTML::Template サンプルプログラム
戻る
# stanadard.pl
# 07.11.28
use strict;
use HTML::Template;
my(%t,@fld,$n,$template,@loop,$s_ref);
open(IN,"names.txt") or die "Can't open the file names.txt\n";
while(){
@fld = split;
next unless $fld[2];
push(@{ $t{namee} },$fld[2]);
push(@{ $t{namec} },$fld[3]);
}
close(IN);
for $n ( 0 .. $#{ $t{namee} } ) {
$$s_ref{e1} = $t{namee}[$n];
$$s_ref{c1} = $t{namec}[$n];
($s_ref) = write2html($s_ref);
}
sub write2html {
my($s_ref) = @_;
my(%t,$n);
$t{e1} = lc($$s_ref{e1});
$t{inputf} = $t{e1} . '.txt';
$t{outputf} = $t{e1} . '.htm';
$t{template} = HTML::Template->new(filename => "index.html");
@loop = ();
$t{flag} = 1;
open(IN,"$t{inputf}") or die "Can't open the file $t{inputf}";
while(){
next if $. == 1;
next if length($_) < 2;
if ( $t{flag} == 1 ) {
$t{flag} = 2;
push(@{ $t{N1s} },$_);
} elsif ($t{flag} == 2) {
push(@{ $t{C1s} },$_);
$t{flag} = 3;
} elsif ($t{flag} == 3) {
push(@{ $t{E1s} },$_);
$t{flag} = 1;
}
}
close(IN);
for $n ( 0 .. $#{ $t{N1s} } ) {
$t{N1} = $t{N1s}[$n];
$t{c1} = $t{C1s}[$n];
$t{e1} = $t{E1s}[$n];
my %row = (
N1 => $t{N1},
C1 => $t{c1},
E1 => $t{e1}
);
push(@loop, \%row);
}
$t{template}->param(namec => $$s_ref{c1});
$t{template}->param(namee => $$s_ref{e1});
$t{template}->param(std_loop => \@loop);
open(OUT,">$t{outputf}");
print OUT $t{template}->output;
close(OUT);
print "The output file is $t{outputf}\n";
return($s_ref);
}
--------------------------------------------------------------------------
()
()
ASME |
BS |
DIN |
GB |
IEC |
IEEE |
ISO
返回
--------------------------------------------------------------------------
# product.pl
# 07.12.01
use strict;
use HTML::Template;
my(%t,@fld,$n,$template,@loop,$s_ref);
open(IN,"products.txt") or die "Can't open the file products.txt\n";
while(){
@fld = split;
if ( /^SH/ ) {
my %row = (
code => $fld[0],
ld => $fld[1],
length => $fld[2],
air => $fld[3]
);
push(@loop, \%row);
}
}
close(IN);
$t{template} = HTML::Template->new(filename => "products0.htm");
$t{template}->param(LOOP => \@loop);
open(OUT,">products.htm");
print OUT $t{template}->output;
close(OUT);
戻る