Kurinchi Blogger Scribbles …

Posts Tagged ‘Perl’

Apr 30

Perl: How to debug in Perl?

Last updated: April 30th, 2010

Turn on warnings by
use warning;

To run a perl script with warnings, type -w with the shebang as in
#!/usr/bin/perl -w
print “Content-type: text/html\n\n”;
print “Hello World\n”;

Check if you have the following line in the program
print “Content-type: text/html\n\n”;
This will output the text to the browser from the server.

Print error messages to the browser using
use CGI::Carp qw(fatalsToBrowser);

The other way is to use the print command to debug your program.

Common error messages
» The specified CGI application misbehaved by not returning a complete set of HTTP headers.
» Can’t locate missing-file.pm in @INC (@INC contains: ….. )

Aug 16

Premature end of script headers: apache error

Last updated: August 11th, 2009

Apache errors and the approach to solve it

Premature end of script headers
500 Internal Server Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.

Some troubleshooting tips:

i) Check /var/log/apache2/error.log (in ubuntu, check the respective apache error log location for the messages)

ii) Check if the content type of the page is correctly set for the html content output.

print “Content-type: text/html\n\n”;

iii) Check if a valid permission has been given for the file to get executed. The file need permission 755 for it to be executed on the server.

iv) Check if the configuration path, inclusion path are set correctly in the referenced programs

Aug 15

Permission denied: exec of failed in Apache Server

Last updated: August 11th, 2009

Apache Permission Denied Error can be caused due to one of many configuration mistakes listed below

Check the apache configuration settings

i) The first is the reference to folder where cgi or perl files will reside and its execute permission settings

 <ScriptAlias /cgi-bin/ /usr/local/cgi-bin/>
 <Directory "/usr/local/cgi-bin">
     AllowOverride None
     Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
     Order allow,deny
     Allow from all

ii) The second is the proper add handlers that are set for the file execution

AddHandler cgi-script .cgi .pl
<Files ~ "\.pl$">
    Options +ExecCGI
<Files ~ "\.cgi$">
   Options +ExecCGI

Check the apache error log for any messages (/var/log/apache2/error.log).

Apr 28

CGI Vs. Perl … What then is CGI?

Last updated: April 28th, 2009

CGI is not a programming language. It is a standard programming interface which gives a web page the capability to run/access other resources on the server(s) which visitors wouldn’t have direct access to.

Perl is a scripting language. It is often misconceived to be the same as CGI, as Perl was the popular language at the time when CGI gained momentum in the web world.

CGI can refer to a “scripting language” which gets interpreted when calls to a page from the webserver is being made. It can be referred as a “program“, when it gets executed on the webserver to have access to resources with hard coded paths other programs when a call from a web page happens.

In short, all Web applications built using ASP/PHP/Python/Perl speaks through the channel – CGI.

Valid HTML 4.01 Strict  Valid HTML 4.01 Strict