Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Starting with Perl

by radiantmatrix (Parson)
on Jul 26, 2005 at 13:58 UTC ( #478196=note: print w/replies, xml ) Need Help??


in reply to Starting with Perl

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://478196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-06-17 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (84 votes). Check out past polls.

    Notices?