tags:

views:

229

answers:

4

Do not you know a method to carry out the following code like php?

<html>
<?perl
print( 'test' );
?>
</html>
+11  A: 

using HTML::Mason:

<%perl>
use Date::Calc;
my @today  = Date::Calc->Today();
my $str = "$today[0]-$today[1]-$today[2]";
</%perl>

<html>
<body>
Today is <%$str %>
</body></html>

Apache Config:

PerlModule HTML::Mason::ApacheHandler
<Location /usr/local/apache/htdocs/mason>
SetHandler perl-script
PerlHandler HTML::Mason::ApacheHandler
</Location>
bb
+7  A: 

The syntax is a little different, but that's the approach used by HTML::Mason.

Personally, I prefer a templating system that encourages more separation of code and presentation. Template Toolkit does that while allowing flexibility to do just about anything you'd ever want to do.

ysth
At my last job the major product we worked on used Mason AND Template Toolkit. Figure that out.
friedo
+2  A: 

There's also EmbPerl though it is not too widely used.

DVK
+1  A: 

While you can embed Perl directly into a Template Toolkit file:

[% PERL %]
use Date::Calc;
my @today  = Date::Calc->Today();
my $str = "$today[0]-$today[1]-$today[2]";
[% END %]

<html>
<body>
Today is [% $str %]
</body></html>

A better way is to use a Plugin:

[% USE date %]
<html>
<body>
Today is [% date.format(date.now, format = '%d-%b-%Y') %]
</body></html>
Brad Gilbert