in reply to Perl and SSI

The problem is that, AFIAK, Apache won't parse script output. At the point that it executes your script, it washes its hands of the matter and assumes that your script will handle its own output.

One question I have for you is: if your script is processing these files, why do you need SSI? Why not include the file yourself? You already know the filename, so just slurp it into a list and print it out at the right place.

There are also modules on CPAN you could have a look at - specifically CGI::SSI.

Replies are listed 'Best First'.
Re: Re: Perl and SSI
by Anonymous Monk on May 02, 2003 at 13:23 UTC
    Please explain what you mean by putting it in a list and printing it out at the right place. I'm not familiar with this?

    The document that the SSI command will process will change, depending on which link is selected. The shtml document is being used as a template and the course description file ($course_desc variable) is the text that describes the course, which will change depending on which course a student selects. So, this information changes, but the basic format of the html document (from the template) does not change. If there is away of importing this information besides using SSI I'm game.

    Thanks,

      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.