zealf has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, does anyone have any ideas on how I can test my scripts.

I am running winxp with my host being ya typical nsca running cpanel.
My problem is that they don't allow Telnet connections.
Being a new to CGI and perl I'm banging my head trying to get the simplist scripts running. Even a helloworld gives me a 500 error. Before you say learner, these are the things I'm tripple checking.

The path to perl is correct as per my host.
My files are in the correct folder.
Permissions are 755.
And of course my host allows CGI scripts.
Further more I can successfully run these off of my machine using a command window.

Replies are listed 'Best First'.
Re: Testing scripts
by Anonymous Monk on Feb 07, 2010 at 10:39 UTC
Re: Testing scripts
by planetscape (Chancellor) on Feb 07, 2010 at 18:42 UTC
Re: Testing scripts
by NetWallah (Canon) on Feb 07, 2010 at 17:00 UTC
    Check your "Shebang line".

    CGI scripts should start with something like:

    #!/usr/bin/perl print "Content-type: text/plain\n\n"; print "Hello World!\n";
    (Assuming your web server is *nix. If it is Windows, the path to perl needs to be set appropriately: #!c:\path\to\perl.exe. )

    For effective debugging, if you use IE, you should turn off "Friendly HTTP error messages" because they hide root cause.

    For instructions, see http://www.communitymx.com/content/article.cfm?cid=a66b8 .

         Theory is when you know something, but it doesn't work.
        Practice is when something works, but you don't know why it works.
        Programmers combine Theory and Practice: Nothing works and they don't know why.         -Anonymous

Re: Testing scripts
by Khen1950fx (Canon) on Feb 07, 2010 at 12:14 UTC
    What editor are you using? You'll want to use an editor that saves the script in pure ASCII text; also, you'll need to upload the CGI script in ASCII mode to the cgi-bin directory.
      cgi-bin directories are not used universally. The OP may not need to put his code in one.

      To the OP: As already said, check your error logs, assuming your hosting company makes them available to you. They should contain the full details of any warnings or error messages emitted by your code.

      The 500 Internal Server Error results you're seeing most likely mean that either the server is failing to run your CGI code at all or that it exits (whether "successfully" or not) without outputting anything recognizable as HTTP headers. When you run your script on the command line, what is its output?

        Running under my windows command line on my machine my simple scripts work fine.
        However so far I have found that
        print <<"ending_print_tag";
        blaaa blaaa
        ending_print_tag
        returns a "can't fint string terminator error "ending_print_tag" anywhere before EOF"
        Any chance you would know what this means?
        BTW this is my current level, gradually improving!
Re: Testing scripts
by scorpio17 (Canon) on Feb 08, 2010 at 14:56 UTC

    Get a better web host.

    No, seriously! I know that sounds snarky, but some web hosting companies really don't want customers doing anything other than uploading plain html. Some hosts say they support perl scripts, but what they mean is that you can choose to activate a small selection of canned scripts they provide (page counter, guestbook, email form, etc.) - not write your own. If you're developing a site that uses perl, then you need a host that supports perl.

    (try clicking the add banner at the top of this page, for example).

    This is why PHP has become so popular. It tends to work with many of the 'HTML only' web hosts, since you include it in the html. If you can't change hosts, this (unfortunately) may be an alternative to consider.

      THANK YOU!


      I have thought this may have been the case for some time. Literally smashing my head agaist the wall trying to get the simplist scripts working only to find my host given scripts work perfect.
      Not having access to Telnet is a real arse. I am currently half way through a tutorial from http://www.softlookup.com
      Very informative but lacking some valuable information like what file named and extenstion each script should be and it also relies heavily on a command line testing.

      Time to go learn the ways of the Perl Monks!