in reply to Create a html page on fly
and as a style thing if you only have trivial amounts of HTML you could:
my $path = "tmp/$filename"; open my $htmlOut, '>', $path or die "Can't create $path: $!\n"; print $htmlOut <<HTML; <HTML> <head> <title> Second page </title><br> $t->{title}<br> $t->{phone}<br> </head> </HTML> HTML close $htmlOut;
which makes the HTML a lot easier to see. Note too the use of three parameter open and lexical file handles.
If you have larger lumps of HTML you should think about using one of the templating modules. My pick for light weight HTML templating is HTML::Template. Your code would look like:
use strict; use warnings; use HTML::Template; my $template = <<HTML; # Normally in an external file <HTML> <head> <title> Second page </title><br> <TMPL_VAR name="title"><br> <TMPL_VAR name="phone"><br> </head> </HTML> HTML my $tmpl = HTML::Template->new(scalarref => \$template); $tmpl->param(title => "Sir Robin", phone => '555-123-45678'); print $tmpl->output();
and print:
<HTML> <head> <title> Second page </title><br> Sir Robin<br> 555-123-45678<br> </head> </HTML>
The idea here is that it is much easier to maintain the HTML without worrying about the code that finally generates it, and much easier to maintain the code without worrying about the HTML.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Create a html page on fly
by mailmeakhila (Sexton) on Mar 19, 2012 at 15:22 UTC | |
by marto (Cardinal) on Mar 19, 2012 at 15:31 UTC | |
by Anonymous Monk on Mar 19, 2012 at 15:48 UTC | |
by mailmeakhila (Sexton) on Mar 19, 2012 at 16:33 UTC | |
by Anonymous Monk on Mar 19, 2012 at 16:40 UTC | |
by tangent (Parson) on Mar 19, 2012 at 19:03 UTC |