in reply to How to use Perl in HTML Template?

please read How (Not) To Ask A Question.
$ cat temp.tt [% PERL %] [ print "Hello!!";] [% END %] <html> <title> This is Example of using perl with HTML </title> </html> $ tpage temp.tt perl error - EVAL_PERL not set $ tpage --eval_perl temp.tt undef error - syntax error at (eval 11) line 3, at EOF $ cat temp.tt [% PERL %] print "Hello!!"; [% END %] <html> <title> This is Example of using perl with HTML </title> </html> $ tpage --eval_perl temp.tt Hello!! <html> <title> This is Example of using perl with HTML </title> </html> $
Template::Tools::tpage, Template::Manual::Directives#PERL

Replies are listed 'Best First'.
Re^2: How to use Prel in HTML Template??
by Sachin (Acolyte) on Nov 03, 2009 at 10:46 UTC

    Thanks Monks for reply and it's working. Now i change the file a little more and got message "Error:EVAL_PERL not set". Could you tell me how to set EVAL_PERL in template . Another issue is that when i run program B it's showing the value of random but in Program A it it not showing the Value of random A.

    Program A

    [% TRY %] [% PERL %] use WebService::CaptchasDotNet; my $o = WebService::CaptchasDotNet->new(secret => 'secret', username => 'demo'); my $random = $o->random; print "random=", $random; my $url = $o->url($random); print $url; [% END %] [% CATCH %] Error:[% error.info %] [% END %] <html> <title> This is Example of using perl with HTML </title> </html>

    Program B

    #!/usr/bin/perl use strict; use warnings; use WebService::CaptchasDotNet; my $o = WebService::CaptchasDotNet->new(secret => 'secret', username = +> 'demo'); my $random = $o->random(); print "Random value = ". $random; my $url = $o->url($random);
      EVAL_PERL needs to be set (or not - I'd advise against putting non-display logic into your templates) in your call to Template->new. e.g.,
      my $tt = Template->new( INCLUDE_PATH => 'tpl/', TRIM => 1, WRAPPER => 'wrapper.tt', EVAL_PERL => 1, );

      Also, you might want to consider changing your question's title... You're doing this with Template::Toolkit, but there's a different (and unrelated) Perl templating module called HTML::Template. I originally read your question expecting to answer that HTML::Template doesn't support Perl in templates at all.

      Could you tell me how to set EVAL_PERL in template .

      Please don't do that. Create a Template::Plugin instead