If you're using Text::Template (and I assume other templating modules will allow you to do the same/similar thing), just replace your the SSI in your template: <!--#include virtual="/crs_desc/%%course_desc%%"/ --> with the code to include the file:

<% my @contents = (); open (FH, "<", "$course_desc") || die "can't open file: $!"; @contents = <FH>; close FH; $OUT .= @contents; %>
Then you can fill in the template from your script, and your includes will be there:
my $q = CGI->new; my $course_desc = "/courses/csci_xxx.txt" if ($q->param('course') eq " +csci xxx"); ... my $tmpl = Text::Template->new(TYPE => "FILE", SOURCE => $template_src +, DELIMITERS => ['<%', '%>'], UNTAINT => 1) || die ("Error loading template $filename: $Text::Template::ERROR +"); my $output = $tmpl->fill_in(HASH => { course_desc => $course_desc}); print "Content-type:text/html\n\n", $output;

Of course, this can get very complicated, especially since virtual includes are used to include the output of commands, etc. This type of very dirty solution is only suitable for very simple cases - and some might argue (successfully) that it should not be used even then.

To be honest, I've only used this approach for static files, such as including a header or footer in a template. This approach may or may not be suitable for what you want to accomplish, but if you're doing anything complex, I would suggest using CGI::SSI.


In reply to Re: Re: Re: Perl and SSI by glivings
in thread Perl and SSI by chriso

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.