Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-06-20 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (93 votes). Check out past polls.

    Notices?