Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

SSI includes vs. require

by juanmanuel (Initiate)
on Apr 05, 2006 at 17:56 UTC ( #541465=perlquestion: print w/ replies, xml ) Need Help??
juanmanuel has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks

My first post at the monastery, I hope it doesn't hurt too much =).

I have some subs that I would like to include in various CGI scripts. From what I've read so far, I could include them with...

<!--#include virtual="...

What would be the difference between the SSI command and just pulling the sub in with a require operator?

Please donít hesitate to point me in the right direction if this topic has been touched before.

Thanking you in advance for your patience and wisdom,


Juan Manuel


Thank you everyone for your kind advice. I'm looking forward to the assigned homework!

Comment on SSI includes vs. require
Download Code
Re: SSI includes vs. require
by kutsu (Priest) on Apr 05, 2006 at 18:13 UTC

    For one virutal includes just run the cgi-script and print the output so you can't specify a sub (well you could with some params, but that could get convulted). Secondly virtual includes are more for html files that don't have execute permission already, and are nice for including html templates (like a header file) for example, and will proably just cause a syntax error in a cgi script (will when testing over the command line at least). Require just includes the perl-script in a perl script so you could call the subs normally like they were in the same file.

    You should look at Simple Module Tutorial for an even better way to include separate sub routines in multiple perl-scripts. Oh, Welcome to Perlmonks too :).

Re: SSI includes vs. require
by CountZero (Bishop) on Apr 05, 2006 at 18:41 UTC
    Welcome to the Monastery Juan! May you spend many an hour here and increase you knowledge of Perl in manifold ways, finally giving back more to our community than you have ever received.

    Now to your question.

    I gather that you wish to create some dynamic web-pages. SSI is indeed one way to do so, but it is not the most flexible. As already said it will simply include the output of a script or file (which could be a Perl script or anything else which can be run in your webserver and provides output).

    A much more useful, flexible and interesting way of making dynamic websites is by using a templating system such as The Template Toolkit (but there are many others) or by handcrafting your HTML through Perl and the CGI-module. Have a look at these and see how infinite the possibilities are for using Perl in the World Wide Web!

    And of course the not-to-be-missed CGI-course of Ovid is a good start.


    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: SSI includes vs. require
by stonecolddevin (Vicar) on Apr 05, 2006 at 19:03 UTC
Re: SSI includes vs. require
by leocharre (Priest) on Apr 05, 2006 at 21:00 UTC

    this is some raw info.. just to help out..

    Subs are chunks of reusable code. By themselves they are little use other then as text in your html

    scripts. programs, use subs to do stuff.

    if you do an include

    you know how you could have a script that spits out part of something you may want to use in an html document- you could make a script called .. say... header.cgi - that just creates a header for your html document. Maybe you have a script that generates a calendar.. cal.cgi .. so you would maybe do this..

    <!--#include virtual="cgi/cal.cgi"--> and then you get your calendar on the shtml page. You may want to play with passing parameters in the query string to that.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://541465]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2014-10-31 15:17 GMT
Find Nodes?
    Voting Booth?

    For retirement, I am banking on:

    Results (219 votes), past polls