Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
... 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":



  • 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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

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

    No recent polls found