HTML::Templateを使ってみよう
yaino.comさんのサイトが丁寧な解説でしたので
http://yaino.com/gzudoc2/0001/000013.html 解説を読んでみてね。
ここのサンプルコードを改造してみます。
http://localhost/sample1.pl と打ったときに
と表示されるようにしてみます。
sampie1.pl の中は こんな感じに
#!D:/xampp/perl/bin/perl -w #Cドライブの人はCにしてください use HTML::Template; my $tmpl = HTML::Template->new( die_on_bad_params => 0, filename => 'sample1.htm' ); my @user_data =( {data_code=>1947,data_name=>'誕生'}, {data_code=>1969,data_name=>'東京大学工学部応用物理・計数工学科卒業'}, {data_code=>1976,data_name=>'スタンフォード大学大学院博士課程修了'}, {data_code=>1981,data_name=>'専修大学助教授'}, {data_code=>1986,data_name=>'第38回衆議院議員総選挙(旧北海道4区・自民党公認)当選 '}, {data_code=>1993,data_name=>'自民党離党'}, {data_code=>1994,data_name=>'新党さきがけ結成'}, {data_code=>1998,data_name=>'民主党結成'}, {data_code=>2005,data_name=>'幹事長就任'}, {data_code=>2009,data_name=>'民主党代表、第93代内閣総理大臣就任'}, ); #------------------ # パラメータの設定 #------------------ $tmpl->param(user_name =>'鳩山由紀夫'); $tmpl->param(arr_data =>\@user_data); $tmpl->param(arr_data_num=>scalar(@user_data)); #----------------- # 出力 #----------------- print "Content-Type: text/html\n\n"; print $tmpl->output();
これを組み込む sample1.htm は こうしてね。
<html>
<h1>政権交代</h1>
<h2>どうなる日本</h2>
年表 -- 経歴
データはありません