mezz has asked for the wisdom of the Perl Monks concerning the following question:

Hey there, I am wondering how can I get SSI tag works in the Perl script? Do I have to enable the Apache? Also, I would like to know what string to enable it in the .htaccess. The currently SSI only will works if the file name is *.shtml.
#!/usr/bin/perl print "Content-type: text/html\n\n"; print <<HEADER; <!--#include virtual="/blah/header.txt" --> HEADER
Thanks, Mezz

Replies are listed 'Best First'.
Re: How can I get SSI tags works in Perl script?
by Masem (Monsignor) on Jul 20, 2001 at 05:29 UTC
    By default, dynamic output is not re-parsed for SSI inclusion (or any other 'after-effects'). However, two ways exist to use SSI (or it's near equivalent). Either use the module CGI::SSI which allows you to call SSI from the perl script, or use a templating solution such as HTML::Template, Template Toolkit 2 or HTML::Mason that can be used to include fixed parts of other files before sending the page off.

    ----------------------------------------------------- Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

(ichimunki) Re: How can I get SSI tags works in Perl script?
by ichimunki (Priest) on Jul 20, 2001 at 05:33 UTC
    If you are using Perl, you really don't need to also use SSI, unless your ISP has a bunch of prebuit SSI's for you to use. Here's my untested code for this:

    #!/usr/bin/perl -w use strict; use CGI qw(:standard); print start_html(); open( TEXT, "</blah/header.txt" ) or die "missing text file: $!"; my @insertion; while( <TEXT> ) { chomp; push( @insertion, $_ ); } close TEXT; print p( join( '', @insertion ) ); print end_html();


    or something like that. There's lot of ways to do it, but CGI is a good habit to get into for all of them.
      Yes, you are right about it. It can be open the file then print instead of using SSI tag. I never thought of it.

      Umm, about CGI:SSI, I think it's useless because not many host has the moducle for it.

      Thanks guys! =0)

      Mezz
        You can always install modules in your own directory assuming you already have CGI going. You have to play with @INC and a few other details but just because the server doesn't have a certain module installed is no reason not to use it.

        ----------------------------------------------------- Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Re: How can I get SSI tags works in Perl script?
by HyperZonk (Friar) on Jul 20, 2001 at 05:29 UTC
    Lots of information about that subject can be found here. The brief answer is that you can get Apache to parse .html files, but you need to do a few things (chmod and edit your httpd.conf). Your question seems to be about the file name itself, as opposed to Perl issues. If I'm wrong, Masem posts good advice above.

    Update: ichimunki pointed out to me that you were actually trying to include an SSI in Perl output. <notetoself>Read the Fine Code</notetoself> ichi's suggestions below are what I would recommend, personally, but as I stated in the original post, Masem notes CGI::SSI will help you do what you originally planned.