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


I'm new to Perl and wanted to know if there was a way to use SSI within a Perl CGI script? Basically, the CGI script is being referenced from a web page, which is passing it several variables. Based on those variables, I am running several conditional statements to determine which information to present to the user dynamically via SSI.

Any help would be GREATLY appreciated!



Replies are listed 'Best First'.
Re: SSI within a Perl CGI script
by Sinister (Friar) on Mar 11, 2002 at 16:55 UTC
    I once created a toy module for this, which can parse and handle SSI's and #IF-#ELSE's for Apache.

    It can be found here.

    It is called, OO based and un-documented. (The source is still the documentation)
    I hope it can help you.

    er formait hyarya.
    "Field experience is something you don't get until just after you need it."
      No offense, but with modules for SSI already available on CPAN I can't see a good reason to use something that's not documented.

      Try CGI::SSI or CGI::SSI_Parser, or look at this node for more ideas.

        Thanks everyone for your quick replies!

        Regarding the CGI::SSI module, how do I actually use that? Again, excuse my ignorance, but I am new to using Perl and I'm not 100% clear on how to reference the code.

        Do I save all of the CGI::SSI code to a new file and then reference that module from my script, or paste this new code into my script?

        If anyone has a simple example that they could share with me I would be grateful.



Re: SSI within a Perl CGI script
by talexb (Chancellor) on Mar 11, 2002 at 16:49 UTC
    A Server Side Include is just a line of HTML. So if the Perl CGI script is outputting the contents of a web page, adding an SSI directive has no special meaning to Perl.

    Just output the SSI like any other piece of a web page.

    Update:Sinister is right, an SSI is not just a line of HTML -- it is further processed by the web server. But it still does not have any special meaning to a Perl script.

    --t. alex

    "There was supposed to be an earth-shattering kaboom!" --Marvin the Martian

      Not quitte true! A server-side include is parsed by the webserver. What perl returns is no further parsed by your $WEBSERVER.

      er formait hyarya.
      "Field experience is something you don't get until just after you need it."

        Only if your webserver supports it. If you are using apache (as most people do), you will need to use 2.0 (still in beta) if you want your cgi output to be server-parsed.