To add to the advice from tchatzi.

The first time I came across Perl I was in a very similar situation to yourself. Perhaps the experiences I had maybe helpful.

Only make one small change at a time. You'll stand a better chance of having something that still works.

A point often made is that, as much as possible, keeping code and HTML separate makes maintaining both easier. A first step could be at least moving it all to the end of the script. Have a sub that returns the HTML.

my $name = 'John'; my $html = get_html(); # sub name corrected # later... sub get_html{ my $html = <<HTML; <html> <head> <title>my html</title> </head> <body> <p>Hi there $name</p> </body> </html> HTML return $html; }
The next step I took was to replace the variable with an HTML comment.
<p>Hi there <!-- name --></p>
and then the code would look something like
my $html = get_html(); $html =~ s/<!-- name -->/$name/;
The advantage here is that Frontpage can happily use the HTML.

After that it wasn't long before the HTML ended up in a file.

my $html; { local $/; my $file = 'template.html'; open my $fh, '<', $file or die "can't open $file to read: $!"; $data = <$fh>; close $fh or die "cannot close $file: $!"; }
This way you can maintain the HTML in FrontPage.

Once you get to this stage you start to realise you have trod a well worn path! Many have gone before you. As scooterm pointed out above there are many template modules available. I now use HTML::Template and find it excellent.

There are many other aspects of cgi scripts you may want to consider (there is a very good module for that too).

Hope this is of help. If after looking through the docs you still hit some snags (I hit plenty) come back, show what you were trying to do, what you have tried, what you expected. If you do that I have always found the monks very helpful.

Good luck!

update: Corrected name of sub in code snippet


In reply to Re^3: inserting HTML file in a PERL script by wfsp
in thread inserting HTML file in a PERL script by thetallblondguy

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.