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