calling perl from html page

calling perl from html page

am 02.01.2008 21:11:20 von Moti

Hi,
I'm new to perl and have written a script that I want to run on my web
site. My script gets some text lines and parse them.

I've written a html page that conatins a TEXTAREA and a submit button.
I want to paste some text lines inside the TEXTAREA, Then press the
submit button to call my perl script (with the text in the TEXTAREA as
input) .

My questions are:
1) How can I call my perl script from the html page ?
2) Can I do it on my PC or do I need to upload it to the server ?

Thanks in advance, Moti.

Re: calling perl from html page

am 02.01.2008 21:32:18 von Gunnar Hjalmarsson

Moti wrote:
> I'm new to perl and have written a script that I want to run on my web
> site. My script gets some text lines and parse them.
>
> I've written a html page that conatins a TEXTAREA and a submit button.
> I want to paste some text lines inside the TEXTAREA, Then press the
> submit button to call my perl script (with the text in the TEXTAREA as
> input) .
>
> My questions are:
> 1) How can I call my perl script from the html page ?

By making the script URL the action attribute in the form element. Example:







> 2) Can I do it on my PC or do I need to upload it to the server ?

You can do it on your PC if you have a web server (and, of course, Perl)
installed. Assuming you are on a Windows PC, go to
http://www.indigostar.com/indigoperl.htm for the easiest way to get both.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: calling perl from html page

am 02.01.2008 21:38:25 von Joost Diepenmaat

Moti writes:

> Hi,
> I'm new to perl and have written a script that I want to run on my web
> site. My script gets some text lines and parse them.
>
> I've written a html page that conatins a TEXTAREA and a submit button.
> I want to paste some text lines inside the TEXTAREA, Then press the
> submit button to call my perl script (with the text in the TEXTAREA as
> input) .
>
> My questions are:
> 1) How can I call my perl script from the html page ?

You generally install your script as a CGI script or use mod_perl or
some other more or less server-specific system. CGI is probably the
easiest to learn and certainly the most portable. See the manual page for
the standard CGI module. Type

perldoc CGI

at your command prompt or see http://perldoc.perl.org/CGI.html

See also: http://perlmonks.org/?node_id=519640

I wish I could give you a pointer to a really good perl/cgi tutorial but
it's been ages since I looked at one and I can't seem to find any right
now. Most of what you'll find with google is utter crap. At least you
should know a *bit* about how HTTP (the protocol that powers the web)
works, and then the CGI documentation should make more sense.

This seems OK: http://www.jmarshall.com/easy/http/

Note that you don't need to know all the details of HTTP, but a general
overview is definitely a good thing to have, since then you'll at least
know 1. what the limitations are and 2. how much work CGI.pm is taking
care of for you :-)

> 2) Can I do it on my PC or do I need to upload it to the server ?

You need to put your script at a server that is reachable by your
audience, if you are the only user, you can put it at your own PC,
otherwise, you need to put it somewhere else or make sure your PC is
reachable from the network. In either case, CGI scripts are run from by
a webserver - they're not standalone programs.

> Thanks in advance, Moti.

You're welcome, :-)

Joost.

Re: calling perl from html page

am 03.01.2008 00:56:36 von Purl Gurl

Gunnar Hjalmarsson wrote:

> Moti wrote:

(snipped a lot)

>> I'm new to perl and have written a script that I want to run on my web
>> site. My script gets some text lines and parse them.

>> 1) How can I call my perl script from the html page ?

>> 2) Can I do it on my PC or do I need to upload it to the server ?

> You can do it on your PC if you have a web server (and, of course, Perl)
> installed. Assuming you are on a Windows PC, go to
> http://www.indigostar.com/indigoperl.htm for the easiest way to get both.

If I may stick my nose in here where my nose does not belong,
I would strongly urge usage of the August, 2002, release of
Indigo Perl for usage with Windows. If not, my second choice
would be the February, 2005, release of Indigo Perl.

The February, 2003, and the March, 2004, versions of Indigo Perl
have a handful of severe bugs which renders running Apache and
PHP on Windows, almost impossible. These are not bugs introduced
by IndigoStar rather are compatibility problems in early Apache 2.x
versions and bundled PHP programming. These two versions, Apache
has serious compatibility problems with WinXP (NT 5) and PHP shows
equally serious compatibility problems with Apache.

Perl runs fine for all versions. For efficiency, first release
of Perl 5.8 is the fastest running. However, there are compatibility
problems with older Perl scripts and older Perl modules. Perl 5.8
runs much slower than earlier versions but offers more features.

For casual usage, for beginners to moderate skill levels, my
sincere suggestion is to use the older August, 2002, version
of Indigo Perl. This version installs quick and easy, and runs
right off with no issues. This early version is really great
and completely painless to install and run.

--
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.

Re: calling perl from html page

am 03.01.2008 21:33:51 von Moti

Hi guys,
Thanks for your great detailed answers.

I installed the indigoperl on my window PC.
Afterwards I tried to test it with an guestbook example code that I
found here:
http://www.bin-co.com/perl/cgi/cgi_guestbook.php

I placed the .html files in the htdocs folder (under the indigoperl
installtion folder) and placed the .pl script in the cgi-bin folder.

I think that the server is up and running but when I try to use the
guestbook.html file to run the guestbook.pl script (by pressing the
submit button) it doesnot work.

I suspect that the path pointing to the .pl script is not correct - it
is: action="\cgi-bin\cgi_guestbook.pl"

Do you have any suggestions ? I dont know what I'm doing wrong
here ...

Thanks in advance, Moti.

Re: calling perl from html page

am 03.01.2008 22:00:25 von Joost Diepenmaat

Moti writes:

> Hi guys,
> Thanks for your great detailed answers.
>
> I installed the indigoperl on my window PC.
> Afterwards I tried to test it with an guestbook example code that I
> found here:
> http://www.bin-co.com/perl/cgi/cgi_guestbook.php
>
> I placed the .html files in the htdocs folder (under the indigoperl
> installtion folder) and placed the .pl script in the cgi-bin folder.
>
> I think that the server is up and running but when I try to use the
> guestbook.html file to run the guestbook.pl script (by pressing the
> submit button) it doesnot work.

We probably need more information that "it doesn't work" for us to help
you. See below.

> I suspect that the path pointing to the .pl script is not correct - it
> is: action="\cgi-bin\cgi_guestbook.pl"

Paths in URLs on any system that I know of require forward slashes, i.e:

/cgi-bin/cgi_guestbook.pl

You should also make sure that either all files in /cgi-bin/ or at least
the files ending in .pl are recognized as executable cgi scripts by the
server.

> Do you have any suggestions ? I dont know what I'm doing wrong
> here ...

If the above doesn't help, take a look at the reports in the server's
error log. That's what it's there for. If you can't figure out what's
wrong from the error log, post whatever info you do have (including any
relevant info from the error log) and we'll see if we can help you :)

Aside: http://www.catb.org/~esr/faqs/smart-questions.html

> Thanks in advance, Moti.

Cheers,
Joost.

Re: calling perl from html page

am 03.01.2008 22:53:30 von Purl Gurl

Moti wrote:


> I installed the indigoperl on my window PC.

> Afterwards I tried to test it with an guestbook example code that I
> found here:

> http://www.bin-co.com/perl/cgi/cgi_guestbook.php

> I placed the .html files in the htdocs folder (under the indigoperl
> installtion folder) and placed the .pl script in the cgi-bin folder.

> I think that the server is up and running but when I try to use the
> guestbook.html file to run the guestbook.pl script (by pressing the
> submit button) it doesnot work.

> I suspect that the path pointing to the .pl script is not correct - it
> is: action="\cgi-bin\cgi_guestbook.pl"

Shut down Apache. Be sure to do this.

Move to your Apache "conf" directory. Using a text editor
open your "httpd.conf" file and read slowly and carefully.
There are lots of good instructions within. There a few, very
few "configurations" you need to make to run cgi scripts.
This is discussed within your httpd.conf file.

Save a backup copy of your httpd.conf file. There is already
a "http.default.conf" which serves as a backup, but make
your own backup to be sure all is safe.

Make changes in your httpd.conf file as instructed within
that file. Save this file.

Restart Apache and check your MSDOS window for error messages.

You _must_ stop Apache, edit, then restart Apache.

This is very easy to do once you learn some very basic
configuration needs.

Here is a page which will help you,

http://www.purlgurl.net/manual/howto/cgi.html

Lots of good information on this Apache documentation page.
There are many easy-to-read tutorials on Apache and cgi
available on the web. Have a look at those, as well.

You will do better to begin with a simple "hello world" script.
Indio Perl also contains example scripts in your cgi bin for use.

On your relative path, action="\cgi-bin\cgi_guestbook.pl"
use a full path until you learn what works and what does not.

action="http://localhost/cgi-bin/cgi_guestbook.pl"

Note I use right hand slashes (/). This is what you should
use. You do not need to use Windows left hand (\) slashes
and you should _not_ use those Windows slashes.

Be sure to carefully study the page I link for you.

Only make very small changes and test. Keep this very simple
as you move along. Should you make a lot of changes at once,
you will become lost. There are only three or four changes
you need to make in your httpd.conf file. All are simple.
This is mostly related to "permission" to run a script.

Do not be discouraged. This configuration stuff is very easy
to learn and you will feel silly once having learned. If you
still have problems, you can ask for help here or go over to
the Apache Configuration newsgroup; many experts there.

Clearly your Apache webserver is up and running, you have
accomplished ninety-five percent of your task. Now you only
need to make a few simple tweaks and learn some very simple
and very basic configuration items; very easy to learn.


--
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.

Re: calling perl from html page

am 03.01.2008 23:10:37 von Purl Gurl

Moti wrote:


> I installed the indigoperl on my window PC.

> Afterwards I tried to test it with an guestbook example code that I
> found here:
> http://www.bin-co.com/perl/cgi/cgi_guestbook.php

Moti, I forgot to discuss this for you.

Do not install scripts then test to determine if Apache
is running.

Start Apache through your windows "Start --> Indigo Perl"
program selections. You should find a "start apache" link.

Start Apache. An MSDOS like window should appear on your
desktop or as an icon on your taskbar. Maximize (open)
this window. You should read "Apache..version stuff..running."
Now minimize (do not close) this window down to your taskbar.

Now open a browser, Netscape, MSIE, whatever, and enter this
URL address into your location bar, then "GO" there,

http://localhost

You will or should see an html page which informs
you Apache is successfully running.

Testing Apache for running, is that simple.

You will find this test page in your "htdocs" directory.
Should be index.html in there.

--
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.

Re: calling perl from html page

am 03.01.2008 23:16:23 von Moti

Guys, thanks again for your replies.
Joost - here are the logs I got as a repsonse for my trys. Maybe it
conatins a hint..

error.log ->
[Fri Jan 04 00:10:40 2008] [error] [client 127.0.0.1] couldn't spawn
child process: c:/indigo/cgi-bin/cgi_guestbook.pl


access.log ->
127.0.0.1 - - [04/Jan/2008:00:10:40 +0200] "GET /cgi-bin/
cgi_guestbook.pl?name=HOUHL&email=JGK&loc=YGFJKG&comments=GH LKJ HTTP/
1.1" 500 602

Purl Gurl - special thanks for your detailed answer I will try to
follow your instructions ...

Many thanks, Moti.

Re: calling perl from html page

am 03.01.2008 23:32:36 von Purl Gurl

Moti wrote:

You are jumping into this with both feet!

Brave boy!


> error.log ->
> [Fri Jan 04 00:10:40 2008] [error] [client 127.0.0.1] couldn't spawn
> child process: c:/indigo/cgi-bin/cgi_guestbook.pl

Typically, this would read to be a permissions problem
or a path to perl problem.

However, look at your error log entry.


> access.log ->
> 127.0.0.1 - - [04/Jan/2008:00:10:40 +0200] "GET /cgi-bin/
> cgi_guestbook.pl?name=HOUHL&email=JGK&loc=YGFJKG&comments=GH LKJ HTTP/
> 1.1" 500 602

Your next to last entry "500" just before your 602 byte count served.

You should see an html page "Internal Server Error" and other info.
There is something wrong with your script. For a cgi script, the
most common problem is not printing a "content type" header. Next
most common is no path or an incorrect path to perl core.

I will urge you again to use a "hello world" script for testing.
Doing so will instantly verify your server is configured to
serve up cgi scripts. Drop one of these into your cgi-bin,


#!perl (your path to perl is here)

print "Hello World!";


This should appear as a plaintext page, no html.


#!perl (your path to perl is here)

print "Content-type: text/html\n\n";

print "Hello World!";


This should appear as an html page.

Once again, I urge you to start out testing with a
simple "Hello World" script to confirm Apache is
correctly configured to serve up cgi scripts.


--
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.

Re: calling perl from html page

am 03.01.2008 23:39:10 von Purl Gurl

Purl Gurl wrote:

> Moti wrote:

(snipped)

> most common problem is not printing a "content type" header. Next


> #!perl (your path to perl is here)

> print "Hello World!";


Very easy to forget a content type. This example
above will cop an internal server error. This
example above should be,


#!perl (your path to perl here)

print "Content-type: text/plain\n\n";

print "Hello World!";


--
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.

Re: calling perl from html page

am 03.01.2008 23:43:36 von Moti

On Jan 4, 12:32=A0am, Purl Gurl wrote:
> Moti wrote:
>
> You are jumping into this with both feet!
>
> Brave boy!
>
> > error.log ->
> > [Fri Jan 04 00:10:40 2008] [error] [client 127.0.0.1] couldn't spawn
> > child process: c:/indigo/cgi-bin/cgi_guestbook.pl
>
> Typically, this would read to be a permissions problem
> or a path to perl problem.
>
> However, look at your error log entry.
>
> > access.log ->
> > 127.0.0.1 - - [04/Jan/2008:00:10:40 +0200] "GET /cgi-bin/
> > cgi_guestbook.pl?name=3DHOUHL&email=3DJGK&loc=3DYGFJKG&comme nts=3DGHLKJ =
HTTP/
> > 1.1" 500 602
>
> Your next to last entry "500" just before your 602 byte count served.
>
> You should see an html page "Internal Server Error" and other info.
> There is something wrong with your script. For a cgi script, the
> most common problem is not printing a "content type" header. Next
> most common is no path or an incorrect path to perl core.
>
> I will urge you again to use a "hello world" script for testing.
> Doing so will instantly verify your server is configured to
> serve up cgi scripts. Drop one of these into your cgi-bin,
>
> #!perl (your path to perl is here)
>
> print "Hello World!";
>
> This should appear as a plaintext page, no html.
>
> #!perl (your path to perl is here)
>
> print "Content-type: text/html\n\n";
>
> print "Hello World!";
>
> This should appear as an html page.
>
> Once again, I urge you to start out testing with a
> simple "Hello World" script to confirm Apache is
> correctly configured to serve up cgi scripts.
>
> --
> Purl Gurl
> --
> So many are stumped by what slips right off the top of my mind
> like a man's bad fitting hairpiece.

Hi Gurl Purl,
Thanks to you (and the other forum members) I've got my guestbook page
up & running. The only problem was the 1'st line in my perl script. It
was: #!/usr/local/bin/perl
When I changed it to: #!perl -w the all thing start working ...

So thanks alot for your prompt reply it was very very helpful.

Have a great weekend, Moti.

Re: calling perl from html page

am 04.01.2008 01:27:06 von Purl Gurl

Moti wrote:

> Purl Gurl wrote:
>> Moti wrote:

>> You are jumping into this with both feet!

> Thanks to you (and the other forum members) I've got my guestbook page
> up & running. The only problem was the 1'st line in my perl script. It
> was: #!/usr/local/bin/perl

> When I changed it to: #!perl -w the all thing start working ...

This is evidence your Indigo Perl installed perfectly,
including adding your perl path to your environment
variables. Indigo Perl is a very nice bundled package
and is easy to install.

There is much you can do with this package, including
running Perl 5.6 and Perl 5.8 within the same directory
structure. This is nice but requires careful work to
install a different Perl without overwriting your
existing files, this includes newer Perl documentation.

You can also install Apache documentation for Apache 2.x
if you currently have Apache 1.x documentation. This 2.x
documentation applies well to the older version.

Nice to read all is working. You will have a lot of fun
with your Apache / Perl installation. Having a test bed
machine, at home, is great for development before loading
to your public webserver; a real time saver.

Won't be long you will be running your own Internet Service
Provider, at home, just like we do.

--
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.