... 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


In reply to Re: templates vs here docs by mwah
in thread templates vs here docs by grashoper

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.