How to troubleshoot Perl scripts

This article describes several ways you can troubleshoot your Perl scripts.

Troubleshooting Perl scripts

When you have a Perl script that is not functioning correctly, you can follow these troubleshooting steps:

Step #1: Verify file permissions

Make sure that the Perl script file has the correct permissions set. Which file permissions you set depends on how the Perl script file is run. For more information about the correct file permissions for Perl script files, please see this article.

Step #2: Verify line break settings

Make sure the Perl script file is in UNIX text format, and not DOS format. The two formats encode line breaks differently, and script files saved in the DOS format may cause syntax errors when they are run.

Step #3: Run the script from the command line

Trying to debug a Perl script through a web browser can be difficult. For example, if you receive an “Internal Server Error”, the root cause could be file permissions, a syntax error, or something else entirely. You can obtain much more useful information about script errors by logging in to your SSH account and running the script from the command line. To do this, type the following the command, replacing filename with the script filename:

perl filename

When there is an error, the Perl interpreter outputs detailed information about the type of error, and often the exact line number in the script file where the error occurred.

If you need even more detailed information or control over the script's execution, you can run the script in the Perl command-line debugger. To do this, type the following command:

perl -d filename

The Perl debugger has many features. For more information about how to use the Perl debugger, please visit http://perldoc.perl.org/perldebtut.html.

Step #4: Check web server error logs

This step only applies to Perl scripts that are run as CGI scripts through a user's web browser. Perl scripts that are run on the command line do not log errors in the web server logs.

Perl scripts that cause a “500 Internal Server Error” or “403 Forbidden” error message are logged in the web server's error log. You can use cPanel to view the error log for your web site.

Get Perl Hosting

Article Details

  • Level: Intermediate

Related Articles

Show More

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.