[100936] in RedHat Linux List
RE: WebServer-CGI scripts: I m running to the Library, but..
daemon@ATHENA.MIT.EDU (Charles Galpin)
Mon Nov 23 20:57:59 1998
Date: Mon, 23 Nov 1998 20:54:39 -0500
From: Charles Galpin <cgalpin@lighthouse-software.com>
To: "redhat-list@redhat.com"@smtp2.erols.com
Resent-From: redhat-list@redhat.com
Reply-To: redhat-list@redhat.com
It was I, your generous linux pal who spoke these words, and who should have
chosen them better.
===== Original Message from redhat-list@redhat.com at 11/23/98 9:43 pm
>Hi,
>I ll follow the advice of one of you who generously asked me to go through
>a book on perl, first, then try to set cgi on my web server.
I was hoping the simple program I sent you would at least let you verify
that your web server and perl were setup correctly so you would have a solid
starting point. Did you get it to work?
>But just
>before running to the library, my generous linux pal said : "
>Your program should compile
>cleanly with perl -c query.pl before you even think about using it as a cgi."
Unlike dos, a file can be a executable without a special extension like .bat
or .pl to run. You set the executable bit on the file (man chmod), and the
operating system does the rest. How? It looks at the file, and if it is a
text file, with #! as the very first characters in it, it knows that this is
a script to be run by some program, often a shell like sh, but in this case
the program "usr/bin/perl". The OS then invokes that program on the file.
So if you type
/usr/bin/perl myperlprog
it is the same as typing
./myperlprog
that has
#!/usr/bin/perl
as the very first thing on the very first line.
The web server does the same thing, it just executes your program after
setting up the environment correctly.
Now compile was a bad choice of words. Perl is a scripting language, but
when you invoke perl, it does parse the code first to ensure there are no
syntax errors. This is actually a nice feature if you've ever written shell
scripts, you sometimes don't discover a bug until way to late.
Anyway the -c switch tells perl to run this parse step, but not execute the
program. It's an easy way of testing if what you wrote is at least valid
syntax. It in no way guarantees it will work. The better you get at perl,
the more likely this is actually true though.
Now back to cgi programs. When you are just starting they are difficult to
test because you cannot just run them from the command line like other perl
scripts because you the web server sets up various environment variables for
you, and as a beginner I just suggest the following strategy. Start small,
and make small incremental changes, testing them frequently. When things go
wrong, there will be only a few lines changed that could be to blame.
>. Just adding that query.pl was a little cgi script I did put in my
>cgi-bin directory and that I ve never been able to run.
>So I just want to know what this person means by "compile cleanly with perl
>-c
>query.pl". Does that mean that it's not enough just to create a cgi-script
>query.pl and hope that it'll work. Should I first launch the
>command "perl -c query.pl" that will compile it..then..Anyway, I ll let
>you give me more clarifications on that.
>
see above. So start with that script I sent you! Dont forget to make it
executable with
chmod +x myperlprog
>A last question: What would you suggest me as a Good perl book, with not
>much theory, but that is all about straightforward indications,
>techniques and bring me quickly and efficiently to a good understanding of
>CGI-Perl dynamic web server set up.
Like I said last time, perl and cgi are often used together, but only
because they go well together, not because they need each other. I often
laugh when I see resumes will perl/cgi on them. :)
I have what's known as the camel book, "Programming Perl" by O'reilly. It is
very good.
It will not teach you cgi programming. I actually learnt it off the web
years ago, so I know there must be ton of resources out there now.
>
>Thanks
>
>Marc
>
Hope this helps
Charles
-- Charles Galpin <cgalpin@lighthouse-software.com>
--
PLEASE read the Red Hat FAQ, Tips, Errata and the MAILING LIST ARCHIVES!
http://www.redhat.com http://archive.redhat.com
To unsubscribe: mail redhat-list-request@redhat.com with
"unsubscribe" as the Subject.