calling perl from html page

Discussion in 'Perl Misc' started by Moti, Jan 2, 2008.

  1. Moti

    Moti Guest

    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.
    Moti, Jan 2, 2008
    #1
    1. Advertising

  2. 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
    Gunnar Hjalmarsson, Jan 2, 2008
    #2
    1. Advertising

  3. 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.
    Joost Diepenmaat, Jan 2, 2008
    #3
  4. Moti

    Moti Guest

    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.
    Moti, Jan 3, 2008
    #4
  5. 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.
    Joost Diepenmaat, Jan 3, 2008
    #5
  6. Moti

    Moti Guest

    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.
    Moti, Jan 3, 2008
    #6
  7. Moti

    Moti Guest

    On Jan 4, 12:32 am, 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=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.
    >
    > --
    > 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.
    Moti, Jan 3, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stu
    Replies:
    2
    Views:
    785
    Rob McAninch
    Apr 6, 2004
  2. Chuck
    Replies:
    0
    Views:
    253
    Chuck
    Jul 5, 2003
  3. pj
    Replies:
    3
    Views:
    281
  4. kath
    Replies:
    4
    Views:
    567
    J. Gleixner
    Apr 9, 2007
  5. Bill H

    Flash calling Php calling Perl

    Bill H, Jun 4, 2009, in forum: Perl Misc
    Replies:
    3
    Views:
    247
    Mark Smith
    Jun 4, 2009
Loading...

Share This Page