Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 6 of 6

This is a discussion on Newbie Perl Help Please in the Shared & Semi-Dedicated forum
I'm having the hardest time to get the simplest Perl script working. I have a file called test.pl in my cgi-bin. It is CHMOD to ...

  1. #1
    IDB
    IDB is offline
    Code Guru
    Join Date
    Jan 2002
    Posts
    140

    Newbie Perl Help Please

    I'm having the hardest time to get the simplest Perl script working.

    I have a file called test.pl in my cgi-bin. It is CHMOD to 755

    -rwxr-xr-x 1 errolian errolian 88 Aug 6 11:49 test.pl

    The file is:

    #!/usr/bin/perl
    #
    # Program to do the obvious
    #
    print 'Hello world.'; # Print a message


    From a shell account (Putty) with Perl works fine:
    jailshell-2.05a$ perl test.pl
    Hello world.jailshell-2.05a$ perl test.pl

    From a shell account (Putty) with no Perl prefix does not work:
    jailshell-2.05a$ test.pl
    jailshell: test.pl: command not found

    In a web browser:
    500 Internal Server Error

    What am I doing wrong?

  2. #2
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    Ok, a few things...

    first off is your $PATH... when you type
    perl test.pl
    Your "executables" path includes /usr/bin so perl ios found, and the perl filter looks in the current directory for the script.

    However, when you just type
    test.pl
    Your "executables" path probably doesn't include your current directory.

    If so, you'll need to type
    ./test.pl

    #2) Look in your error log off of your control panel to give a clue as to what the internal server error is. With that script, it's likely that the error is a "premature ending of script headers" or some such. You need to have this at the very top of the script:
    print "Content-type: text/html\n\n";

    Good luck.

    PS the script might also need to be in cgi-bin, but I'm not sure.
    EDIT: I just re-read your post -- you already said it's in cgi-bin.

  3. #3
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    As Ron siad, the root of your problem is that you aren't sending a Content-type header. Without that the server (and the receiving browser) don't know what kind of data is being sent and therefore don't know how to handle it. Just add

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

    somewhere prefore the "Hello world" line.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  4. #4
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    Hmmm, did I mistypoe something?

    A clarification might be that the content-type printing ought to be somewhere after the #!/usr/bin/perl and probably after your beginning comments lines, but before any other lines that attempt to create output. I think that it's probably best to put it right near the top.

    Also, you might want to consider making your shebang line to include the -w switch to help in some types of debugging:

    #!/usr/bin/perl -w

    Good luck! Let us know what happens.

  5. #5
    IDB
    IDB is offline
    Code Guru
    Join Date
    Jan 2002
    Posts
    140

    Thumbs up

    Yep, content -type was indeed all I needed.

    Thanks for all the help.

  6. #6
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,438
    Originally posted by IDB
    Yep, content -type was indeed all I needed.

    Thanks for all the help.
    You also should be running in tainted mode:
    Code:
    #!/usr/bin/perl -T
    
    use warnings; # instead of -w
    
    # Program to do the obvious
    #
    print "Content-type: text/html\n\n";
    
    my $message = 'Hello html-compliant world.';           # assign a variable message
    
    print '<html><head><title>Hello world</title></head>'; # make it html compliant
    print '<body><p>';
    print "$message";                                      # print the message
    print '</p></body>';
    print '</html>';
    I'm assuming that this script is intended for typical, html output?

Bookmarks

Posting Permissions

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