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]
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.
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
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...
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]
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
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.
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.
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>.
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...
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.
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.
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!