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.

True laziness is hard work

In reply to Re: Create a html page on fly by GrandFather
in thread Create a html page on fly by mailmeakhila

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.