I don't know if anyone will find this useful but I have. I am writing CGIs on a system which has SSI enabled but does not have the CGI:SSI module installed.

I needed SSI for the website that I already had built so here is what I made...Please critique!
sub getInclude { local ($/) = undef; open (SSI, "<$_[0]") ||die "Cannot open $_[0] for reading: $!\n"; my $header = <SSI>; close SSI; return $header; }
Then you can call it with:
$theheader = getInclude($myincludefile);
or, how I have been using it,
print getInclude($myincludefile);

Replies are listed 'Best First'.
Re: Roll Your Own SSI
by Masem (Monsignor) on Mar 27, 2001 at 03:16 UTC
    The one problem with this is that it does not allow for recursive SSI (which can be done at the pure server level); you could probably hack this more and more to have that work, but each addition hack could cause more breakage. But this does work well for if you know exactly what you are including is simply static text that you'd like on all pages including those dynamically generated.

    Two additional solutions if you want to get a bit better:

    • First, just because the system doesn't have CGI::SSI on it doesn't mean you can't use it; simply install that module into space you have access to, add use lib 'location' to make @INC point to it, and then use CGI::SSI.
    • Second, many of the templating systems do inclusion of addition text in a much better way than SSI; I'm currently partial to Template Toolkit 2, myself, but there's Text::Template and HTML::Template as well. Neither is true SSI, but for what most people do with SSI, these work just as well.

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