Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

debuggng PERL

Status
Not open for further replies.

DaveC426913

Programmer
Jul 28, 2003
274
CA
1] How can I reliably debug PERL by displaying the contents of variables? What if the script hasn't actually created a page yet, but might?

The pages I'm debugging are doing various things that might or might not generate an HTML page, redirect to another page or run a shell script. The very act of displaying a variable may mess with the operation of the script (especially if it hasn't printed the header yet).

While I'm at it, same question about shell scripting.



2] I run my PERL script (createdir.pl) but, rather than being redirected, it displays this - I don't understand what it is telling me:

Status: 302 Moved Location:
It should be going to that URL (which does exist). Why isn't it? Does 'moved location' simply mean "I would go there if I could find it"?


Here are the relevant parts of the code (there's other bits, hopefully I've pared them out correctly):

#!/usr/bin/perl -w

use strict; # Activate compile-time syntax checking
use CGI; # Needed for CGI environment
use CGI::Carp qw(fatalsToBrowser); # Throw errors as HTML pages
use File::Copy; # Much easier for duplicating the sample conf

my $thecgi = new CGI;
my ($instructions,$redirect,$code,$clientDB,$clientName,$eventID,$eventName,$mode);
print "Content-type: text/html\n\n";
newEvent();

$code = $thecgi->param("c");
$instructions = "$mode $clientDB $eventID";
$redirect = "

#####
my $cmd = "./createdir.sh $instructions";
my $result = system($cmd);
$result >>= 8; # shift 8 bits

select (STDOUT);
print $thecgi->redirect( $redirect );
exit 0;
#####

function newEvent(){
etc, etc.
}
exit 0;
 
2 is easy, 1 all I can really say is check the FAQ's here and in the CGI forum for a few pointers. Others may chime in with their debugging preferences, but I haven't done much complex stuff with it to be of any help.

You can't print a standard Content-type mime if you're doing a redirect. The redirect itself sends different codes that tell the browser what to do. Otherwise, the browser is just doing what you told it to do ten lines earlier: treat the following content as text/html. (you can/should send that with CGI.pm's header(), too)

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
simple print statements to a logfile are generally what I use for debug information. I tend to use indenting for loops as well.

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top