Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > calling perl from html page

Reply
Thread Tools

calling perl from html page

 
 
Moti
Guest
Posts: n/a
 
      01-02-2008
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.
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-02-2008
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:

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

> 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
 
Reply With Quote
 
 
 
 
Joost Diepenmaat
Guest
Posts: n/a
 
      01-02-2008
Moti <(E-Mail Removed)> 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.
 
Reply With Quote
 
Moti
Guest
Posts: n/a
 
      01-03-2008
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.
 
Reply With Quote
 
Joost Diepenmaat
Guest
Posts: n/a
 
      01-03-2008
Moti <(E-Mail Removed)> 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.

 
Reply With Quote
 
Moti
Guest
Posts: n/a
 
      01-03-2008
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&c omments=GHLKJ HTTP/
1.1" 500 602

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

Many thanks, Moti.


 
Reply With Quote
 
Moti
Guest
Posts: n/a
 
      01-03-2008
On Jan 4, 12:32*am, Purl Gurl <(E-Mail Removed)> 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=HOUHL&email=JGK&loc=YGFJKG&c omments=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.
>
> --
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Flash calling Php calling Perl Bill H Perl Misc 3 06-04-2009 03:32 PM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
problem calling perl script from SOAP server perl script pj Perl Misc 3 04-09-2004 10:23 PM
How to display a html page after the original html page runs a perl script Stu HTML 2 04-06-2004 05:19 AM
Calling a html page from an asp page then returning to the next statement on the original asp page Chuck ASP General 0 07-05-2003 02:00 AM



Advertisments