Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: templates vs here docs

by mwah (Hermit)
on Dec 19, 2007 at 22:25 UTC ( [id://657990]=note: print w/replies, xml ) Need Help??


in reply to templates vs here docs

... using a here doc and xslt transforms for outputting html ...

In the last months or so I wrote a bunch of Perl scripts for compute cluster control - which do lots of wicked rsh's into a cluster an present nice html output to the coworkers.

I started out w/heredocs, then changed that to qq{..}-strings, then throwed the towel and used (sound on) a nice little module called:

HTML::Template

This was a stunning experience, after (short) working through the details, I ended up with a HTML-File per script (same name as the script + .htm) and several very clean and easy readable Perl scripts.

The proloque to the action would be identical across the scripts, in my case that's sth. like:

... $scriptname = ... # the scripts name (my $srv = $ENV{SERVER_NAME}) =~ s/\..+//; # where are we now my $srvloc = "/srv/web/$srv/html"; # assume directory # prepare HTML output my $template = HTML::Template->new(filename => "$srvloc/cluster/$sc +riptname.htm"); ...

the corresponding html would be edited in Dreamweaver (or whatever you like) and look like:

... <td class="pid"> <TMPL_IF idproc> <a href="/cgi-bin/myprocess.pl/ii/<TMPL_VAR NAME="host">/<TMPL_VA +R NAME="pid">" title="[pid No.]"><TMPL_VAR NAME="pid">&nbsp; </a> </TMPL_IF> </td> ...

The variables set in the perl program would show up in the html as

<TMPL_VAR NAME="varname">

and the perl program would set the variables like:

... $template->param( host => $host, cpuid => $cpuid, cpuidcolor => $cpuidtab{$cpuid} ); ... ... print "Content-type: text/html\n\n", $template->output;

where he last line would send the html to the browser.

So that's what I'd recommend. HTML::Template is ideal suited for this kind of CGI-script things.

Regards

mwa

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found