Forum Moderators: coopster & phranque

Message Too Old, No Replies

Perl/CGI SSI basic question

Is there a difference between Perl/CGI and SSI

         

Marguerite

9:01 am on Feb 1, 2007 (gmt 0)

10+ Year Member



Hello everyone

I'm new to Perl/CGI and the forum. I've been lurking for a few days, trawling through old posts, and it's obvious that I'm going to have to ask simple questions, one at a time, to grasp the basics. This question isn't even about scripting.

I very recently removed JavaScript navigation my site and uploaded it to a new host. On their main sales hosting page they state:

Perl/CGI is available.

On their page "What coding languages does your hosting support?" they state:

SSI (shtml) and Perl/CGI are available.

Is there a distinct difference between SSI and Perl-CGI, or is Perl/CGI a means of implementing SSI?

If the two are distinctly different then I will ask 123-Reg exactly what is available to me on my entry level package, but it would be better if I had an idea what I'm talking about!

At the risk of giving too much information, it may be helpful if you knew what I am seeking to do. My site is a tiny, non-commercial, family-orientated hobby. In the past I have used JavaScript to insert dynamic navigation; the usual list of links but normal text for the current section and page instead of linking to itself (simple iteration through an array comparing the current document with the array item). I had already decided to ditch JavaScript because I'm trying to conform to accessibility guidelines and (some / all?) screen readers don't support it. Ultimately, I would like to get back my one-stop scripting functionality for navigation.

Thank you for any help, regards
Marguerite

[edited by: coopster at 1:57 am (utc) on Feb. 2, 2007]
[edit reason] removed hosting specifics [/edit]

phranque

9:50 am on Feb 1, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



first, hello and welcome to webmasterworld, marguerite!

here's the simplified version of SSI:

the server sees a document named something.shtml so it knows to look for include directives among the document markup language.
the include directives are replaced with the text of the included files.

here's the simplified version of perl/cgi:

the server sees a file named comething.cgi so it recognizes it as a server side script.
the first line of this script looks something like:
#!/usr/local/bin/perl
which identifies the scripting language as perl.
the perl script that follows should print a valid document to standard output.

Marguerite

10:48 am on Feb 1, 2007 (gmt 0)

10+ Year Member



Hello phranque, thank you for your FAST reply.

I'm going to learn (big task for me!) then upload a simple test page for SSI and see what happens - it can only succeed or fail<s>.

As always, one question leads to another...

I've seen plenty of include examples for PHP, would you give me the HTML construct for Perl/CGI (where PHP isn't available), or point me to another post please?

Your excellent breakdown has answered my next planned concept question - why is that all perl/cgi code snippets I've seen build the HTML from scratch? Now I have an inkling. Yesterday I installed Apache and ActivePerl on my Win XP box and perhaps I understand now why I can't "call" a cgi script from within the HTML<sigh>.

May I suggest that your reply be posted as a 'sticky' for the completely ignorant. I've been reading through pages of stuff (on this forum and elsewhere) for the past week that didn't explain these simple concepts.

Again, thank you for your help.
Marguerite

phranque

12:50 pm on Feb 1, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



some of what i wrote applies to *nix.
i haven't tried apache on xp nor activeperl, so you will need to solve your specifics for that.

the minimal hello.cgi perl script looks like this:

#!/usr/bin/perl
print "Content-type:text/html\n\n";
print "hello world";

once you get that working you are ready to roll...

Marguerite

1:01 pm on Feb 1, 2007 (gmt 0)

10+ Year Member



Yes, I wondered about the difference between WinXP and the Unix server, but I'll find out if/when I upload.

I think I've found something to play with regarding the call from the SHTML file, but haven't tested it yet -

<!--#include cgi="filename.cgi"-->
or
<!--#exec cgi="filename.cgi"-->

I don't mind falling flat on my face...<s>

[edited by: coopster at 1:58 am (utc) on Feb. 2, 2007]
[edit reason] removed hosting specifics [/edit]

perl_diver

8:02 pm on Feb 1, 2007 (gmt 0)

10+ Year Member



I think you now know that SSI and perl/CGI are not the same thing, but just in case it was not clear: SSI and perl/CGI are two totally different things. Really, perl and CGI are two totally different things too but they have become synonymous to mean the same thing.

Marguerite

8:35 pm on Feb 1, 2007 (gmt 0)

10+ Year Member



Hello perl_diver

Yes, I've been plugging away most of today and have come to a tiny little understanding<s>. I should check out that something works on my host server.

I've been able to run cgi files locally since yesterday, but do you think I could get "include" to work? Nah, not a bit of it... Until it dawned on me, call the file from the browser, not by double clicking the file in Explorer<sigh>.

When the brick wall is in front of you, have a glass of wine - it might help. It's only taken me about 6 hours of checking and rechecking my Apache installation, I should have had the wine at 4pm this afternoon.

For others at the beginning of the learning curve, and you insist on testing on a local drive before uploading, I was able to include .txt, and .cgi (and shtml too) using :
<!--#include virtual="ssi-header.txt" -->
<!--#include virtual="/cgi-bin/hello.cgi" -->

Then open the file according your Apache settings:
[localhost...] - not by double clicking the file.

Now I can start to learn perl or cgi (whichever) to do what I started out to do. It will be frustrating, but I will get there in the end.

Marguerite

perl_diver

2:36 am on Feb 2, 2007 (gmt 0)

10+ Year Member



Well, don't feel bad, lots of people make that simple mistake. When you are running a local http server you have to use a web browser, just like you would on the internet. Pat yourself on the back, 6 hours is pretty good time, other people take days to get as far as you have or quit in frustration.

If by learning perl you mean to actually write scripts, well, unless you are an autistic savant, give yourself a few months to learn the basics, and a couple of years to become competent. Perl is a full blown programing language and is not something you an learn in a few days, like html markup.

But if you are persistent and patient, you can learn your way around perl/cgi scripts and how to use them in fairly short order.

Keep in mind, PHP is really the language of choice these days for internet development. You will find lots of help and resources for PHP, while the perl help is getting thinner and thinner these days, there are still a few good sites where you can find good perl coders willing to help.

I help when I can, but I am really an intermediate level perl coder at best.

Good luck on your journey.

phranque

8:39 am on Feb 2, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



marguerite - you will notice if you double click on a file in ms Explorer to open it up in a web browser the url starts with something like "file:///C:/".
if you open that same file through your local web server it will start with something like "http://localhost/".

the http: protocol uses the server which usually supports server side includes.
the file: protocol opens a file on a local or network drive but knows nothing about include directives.

also, including the cgi script into a shtml file will allow you to see the perl code but it won't let the server process the perl as a cgi script.

Marguerite

8:52 am on Feb 2, 2007 (gmt 0)

10+ Year Member



perl_diver

Thanks for your words of encouragement.

>>unless you are an autistic savant<<

Oh, I wish!

I didn't mean to exaggerate when I said I'd learn Perl; all I meant was that I intend to learn just enough to achieve my aim - and nothing more<s>.

My problem is that I won't implement something unless I understand it, and crucially, can maintain it. So I can't just blindly copy and paste example snippets from elsewhere and install them. Though, of course, I use ANY snippets to help me learn! Unfotunately, all the snippets I've seen are for functionality that I simply don't want, stuff I would call "advanced" but you folk probably think of as basic<s>.

Marguerite

8:58 am on Feb 2, 2007 (gmt 0)

10+ Year Member



phranque

I wish you had been sitting over my should yesterday, or read my mind!

The thing to do is put a shortcut on the desktop, saves typing into the browser each time I test, and there will be plenty of testing.

Oh, have just thought - I've only tested my simple little code in Firefox, I'll have to check Opera and IE...

phranque

10:04 am on Feb 2, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



also, including the cgi script into a shtml file will allow you to see the perl code but it won't let the server process the perl as a cgi script.

i actually "misspoke" when i wrote this.
it's been so long since i used SSI i forgot you could run a script within .shtml using the include directive...

Marguerite

1:23 pm on Feb 2, 2007 (gmt 0)

10+ Year Member



phranque

Along the lines of my last comment to perl_diver, you folk have forgotten more than I will ever know<s>.

Marguerite

1:28 pm on Feb 2, 2007 (gmt 0)

10+ Year Member



I have noticed not one, but two, links have been snipped from my postings. I definitely remember using the first, but sadly not the second.

I would like to apologise to the forum, and to thank the moderator for his/her thoughtfulness in choosing to quietly remove the links rather than berate me.

phranque

11:58 pm on Feb 2, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



it would be useful to read the terms of service [webmasterworld.com] to avoid such issues in the future.
they are reasonable and keep things very civil here.

also you should read the charter and library links for any forum in which you are interested.
most, if not all, have useful information.

also, make generous use of site search [webmasterworld.com].
many issues have a rich archive of information from previous threads.

Marguerite

11:01 am on Feb 3, 2007 (gmt 0)

10+ Year Member



phranque -

Yes, I read the terms of service yesterday when I noticed the snip.

Have used the site search extensively, and am about to do so now before posting another question...

Marguerite

12:18 pm on Feb 3, 2007 (gmt 0)

10+ Year Member



Just a quick note to those you have helped me, I've at last sorted out the code for the navigation. Of course it needs testing on the host server - where it may fall completely flat! - but I'm happy that it works locally.

I used a Perl 5 pdf downloaded from the internet for reference. It was far beyond my requirements, but it outlined the syntax which was what I needed.

coopster

12:48 am on Feb 5, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would like to apologise to the forum

Apology accepted ;) And nice work here, perl_diver and phranque.

I'd like to share one other point, Marguerite, in regards to your original "seeking to do" ...


In the past I have used JavaScript to insert dynamic navigation; the usual list of links but normal text for the current section and page instead of linking to itself (simple iteration through an array comparing the current document with the array item). I had already decided to ditch JavaScript because I'm trying to conform to accessibility guidelines and (some / all?) screen readers don't support it. Ultimately, I would like to get back my one-stop scripting functionality for navigation.

Search engines are going to give you more love (they are going to find you and index you so that when people search for key words in regards to information that you are providing, your site will show up in their search list) for using this approach as they don't read through JavaScript well, if at all.

I guess what I am confirming for you is your choice to move to server-side technologies for providing and managing your navigation. You won't be sorry you did so!