Click to See Complete Forum and Search --> : Perl+html


digital_storm
05-25-2005, 05:13 AM
Hello

How do I embed PERL in HTM in the most nice way?
I have to do alot of controlls so I wonder if I can do anything like JSP:

<html>
.
<td> <% if($condition){;%> Print something out <%};%> </td>
.
.
</html>

Or do I have to controll all statements and make more or less static HTML depending on values like:

my $myhtml;
if(condition1){
$myhtml=' 1..........'
}
if(condition1){
$myhtml=' 2..........'
}
.
.
.
<html>
.
.
$myhtml
.
.
</html>



Thanks in advance!

/D_S

Nedals
05-25-2005, 11:45 PM
When writing Perl scripts it is recomended that you seperate your Perl code and HTML as much as possible. It makes for relatively easy maintainance of a complex site.

You may want to take a look at HTML::Template. It may get you close to your JSP example.

eg: .tmpl file would look something like this.

<html>
.
<td><TMPL_IF NAME="CONDITION1">something out</TMPL_IF></td>
.
.
</html>

and in the .cgi script

my $template = HTML::Template->new(filename => "template.tmpl");
$template->param(
CONDITION1 => ($condition1) ? 1 : 0,
.
.
);

digital_storm
05-26-2005, 02:42 AM
Hello

Thanks I'll try that out!

Best Regards/D_S