Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1
    Junior Member
    Join Date
    Mar 2004
    Posts
    3

    Default need an example of simple perl script + html

    i can't get a simple 'hello' world script to work. i've done the following:
    1) placed the script in the cgi-bin
    2) script's name is hello.pl
    3) its mode is 755
    4) script contents bellow
    5) i've tried running it by going to it directly (www.mydomain.com/cgi-bin/hello.pl) and got a 500 error.
    6) i've tried to use SSI but no include was created.
    7) i've tried changing the script's extention to cgi.

    the "hello.pl" script:
    #!/bin/perl
    print "&lt;HTML><BODY>Perl CGI Hello World!</BODY>&lt;/HTML>";

    as you can probably understand, i have no experience with cgi scripts - only with perl and html.

    any pointer to what i'm doing wrong, or any example that anyone can show me will be very much appreciated!

    thanks,
    uri.

  2. #2
    Senior Member FZ's Avatar
    Join Date
    May 2003
    Location
    Johannesburg, South Africa
    Posts
    1,024

    Default

    I've run into this problem a couple of times myself. The fix is annoyingly simple:

    Code:
    #!/bin/perl
    print "Content-type&#58; text/html\n\n";
    print "&lt;HTML>Hello from Perl&lt;/HTML>";
    All you need to add is line number 2, which is stating (to either the server or the browser, I'm not sure) that the output you are generating (i.e. your next print statement) is HTML and should be interpreted as such.

    Good luck with the Perl coding! Personally, I prefer PHP - it is so much easier, and much more forgiving. Plus, 99% of the time, it generates an error that actually tells you exactly where you have gone wrong, instead of just spitting out an unfriendly error 500.
    Fayez Zaheer

  3. #3
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    Well there is what Fayez mentioned and you have the path to perl set wrong if you are woking on a WestHost account.
    /usr/bin/perl
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  4. #4
    Senior Member FZ's Avatar
    Join Date
    May 2003
    Location
    Johannesburg, South Africa
    Posts
    1,024

    Default

    /bin/perl works too

    Both /bin/perl and /usr/bin/perl are actually symlinks to /usr/local/perl/bin/perl...

    Update: I forgot to mention that you might actually be able to pick up something useful (debugging-wise) if you take a look at /var/log/httpd/error_log.
    Fayez Zaheer

  5. #5
    Moderator wildjokerdesign's Avatar
    Join Date
    Jun 2003
    Location
    Kansas City Mo
    Posts
    5,721

    Default

    Opps ops: my mistake. Was thinking new accounts only allowed the one path and did not even check it. Most likely you are right it is simply the Content Type. I always make that mistake.

    Also something to mention is to make sure that you have uploaded the file in text and not bianary mode. My FTP tends to flip back to bianary mode if I do not watch it.
    Shawn
    Please remember your charity of choice: http://www.redcross.org

    Handy Links: wildjokerdesign.net | Plain Text Editors: EditPlus | Crimson

  6. #6
    Senior Member FZ's Avatar
    Join Date
    May 2003
    Location
    Johannesburg, South Africa
    Posts
    1,024

    Default

    I guess they have created so many symlinks/alternate paths to make sure that people's scripts don't break (i.e. standard paths, paths that were used on 1.0, and so on). It's really messy (i.e. the number of files, understanding where the actual file is, etc.) but it's better not to mess with it in any case.

    Good point bringing up the Binary vs. ASCII mode as well, I remember that giving me problems when I was first getting in to Perl as well (i.e. Perl scripts have to be uploaded in ASCII/text mode).
    Fayez Zaheer

  7. #7
    Junior Member
    Join Date
    Mar 2004
    Posts
    3

    Default

    Thanks guys!
    I'm affraid I've tried everything you've mentioned, but still get the same result.
    I've taken a look at the logfile that you've mentioned and here's what it says:
    (2)No such file or directory: exec of /var/www/cgi-bin/hello.pl failed
    [client 62.90.164.194] Premature end of script headers: /var/www/cgi-bin/hello.pl

    any other ideas?

  8. #8
    Senior Member FZ's Avatar
    Join Date
    May 2003
    Location
    Johannesburg, South Africa
    Posts
    1,024

    Default

    Well, the "Premature end of script headers" is definitely the content-type problem I pointed out, so maybe you did not "implement" it correctly: copy and paste the code I quoted above exactly as is and see if that works?

    Update: coming back to the "No such file or directory: exec of /var/www/cgi-bin/hello.pl failed", after having looked it up, here are a few possible explanations (I've simplifed them):

    1. You are not uploading in ASCII/text mode (i.e. you are uploading in Binary mode). You must upload in ASCII/text mode, or use pico via an SSH session to create your file.
    2. There is a misconfiguration issue in Apache, but this obviously does not apply in this case.
    3. The #!... is not the very first line in the file: it has to be the first line. Also, I think you should remove any excess blank lines (or whitespace) you may have added (e.g. tabs) as I seem to recall some quirkiness with these when I was into Perl scripting.

    If, after the above, you still can't get it working, you could e-mail me your file exactly as it is, and I'll see if it runs on my account.
    Fayez Zaheer

  9. #9
    Senior Member jalal's Avatar
    Join Date
    May 2003
    Location
    Germany
    Posts
    1,377

    Default

    Maybe a silly question, but are you sure Perl is installed?

    "No such file or directory" could mean it didn't find the script, but it seems it did as there was a "premature end of file headers".
    It can also mean the script failed to run correctly, which can be because a) there is no perl, b) the path to Perl is wrong, c) the script is not marked as executable or d) some other error that stops the script from running correctly.

  10. #10
    Senior Member SJP's Avatar
    Join Date
    Aug 2003
    Location
    Orcas, Wa
    Posts
    205

    Default

    Definitely make sure the executable bit is set (#chmod 0755 filename.pl). Also make sure the program is syntatically correct (perl -c filename.pl).

    SJP

Similar Threads

  1. Replies: 4
    Last Post: 05-25-2007, 01:18 PM
  2. Trying to use ImageMagick in a cgi perl script
    By gabriellee in forum CGI Scripts / Perl
    Replies: 1
    Last Post: 08-07-2006, 07:42 AM
  3. Installing Bugzilla on a WestHost VPS
    By sonavor in forum CGI Scripts / Perl
    Replies: 0
    Last Post: 03-28-2006, 11:43 PM
  4. Ban malicious bots with this Perl Script
    By zestgourmet in forum CGI Scripts / Perl
    Replies: 1
    Last Post: 03-08-2005, 05:58 PM
  5. Error running an ImageMagick Perl script
    By maychan in forum CGI Scripts / Perl
    Replies: 2
    Last Post: 12-14-2004, 05:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •