I highly recommend HTML::Template for small projects. It's still a templating system, and gives you the advantages of that, but it's also very light and easy to understand.

Templates are nice because you can spend less time debugging HTML inside Perl. With a template, you can design your layout using HTML-editing tools, then replace variable chunks with template variables. If you're familiar with PHP, HTML::Template will not be difficult. Observe a small chunk of an HTML::Template template:

<p>Hi, you are logged in as <!-- TMPL_VAR NAME=username -->, and you have <!-- TMPL_VAR NAME=new_message_count --> new messages.</p +>

A snippet of Perl to populate the variables in the file (which we'll pretend is named template.html):

use HTML::Template; my $template = new HTML::Template (filename=>'template.html'); $template->param( 'username' => $username, 'new_message_count' => get_new_count($username), ); $|=1; ##unbuffered output is a good idea with CGI print $template->output; ## sends to browser;

As for an equivalent to PHP's include(), read the docs on require. One use of it is like this:

require 'myfile.pl';

The above would load myfile.pl and process its contents.

<-radiant.matrix->
Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

In reply to Re: Starting with Perl by radiantmatrix
in thread Starting with Perl by bjg

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.