Perl: 2007年4月アーカイブ

【Perl】HTML::Template使ってみました。   はてなブックマークに登録  

Movable Typeでも使われているHTML::Templateを使ってみました。

以下のcpanの説明どおりにやったら意外にすんなりできました。(^^)v


例えば、 test.tmpl:


  <html>
<head><title>Test Template</title>
<body>
My Home Directory is <TMPL_VAR NAME=HOME>
<p>
My Path is set to <TMPL_VAR NAME=PATH>
</body>
</html>

そして小さな CGI プログラムを作ります:


  #!/usr/bin/perl -w
use HTML::Template;

  # open the html template
my $template = HTML::Template->new(filename => 'test.tmpl');

  # fill in some parameters
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});

  # send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n", $template->output;

これですべてがうまくいっていれば、ブラウザでそのCGIにいくと、
以下のようなものが表示されます:


  My Home Directory is /home/some/directory
My Path is set to /bin;/usr/bin


以上
CPANの中の方、ありがとうございます。

このアーカイブについて

このページには、2007年4月以降に書かれたブログ記事のうちPerlカテゴリに属しているものが含まれています。

前のアーカイブはPerl: 2007年3月です。

次のアーカイブはPerl: 2007年6月です。