calling perl from html page

M

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.
 
G

Gunnar Hjalmarsson

Moti said:
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:

<form action="http://mysite/cgi-bin/myscript.pl" method="post">
<textarea name="text"></textarea><br>
<input type="submit">
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.
 
J

Joost Diepenmaat

Moti said:
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.
 
M

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.
 
J

Joost Diepenmaat

Moti said:
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.
 
M

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=GHLKJ HTTP/
1.1" 500 602

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

Many thanks, Moti.
 
M

Moti

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=GHLKJ 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 "<HTML>Hello World!</HTML>";

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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top