Subject: Re: Debugging cgi scripts > I haven't written a cgi script in well over a year and I'm > really rusty. I remember I used to know some way to get the > output of a perl cgi to print to the terminal. This was > invaluable for debugging, but I can't recall how to do this. I'd > also like to be able to get my variable values to print out to > the terminal. drop this in at the very start of the script: BEGIN { print "Content-type: text/plain\n\n"; } BEGIN { open (STDERR, ">&STDOUT") or die qq(can't redirect STDERR: $!); } the first line sends an immedate response to the browser, telling it to expect unformatted text. that's probably what you want when debugging, because having error messages bunched together and line-wrapped is a pain in the tuckus. the second line tells the interpreter to send all the error messages, which would normally be written to the error_log (and thus be invisible to you), to standard output. that lets you see what the interpreter is griping about. items in BEGIN{} blocks are executed immediately, in the order they're seen. putting the two operations in separate blocks ensures that the header will *always* be printed, even if the system can't redirect SDTERR for some reason. it should be just this side of impossible for you to get a "510 Internal Error" page if the interpreter even begins to parse the script. between them, those operations let you set the compiler warnings flag: #!/usr/local/bin/perl -w and have the interpreter's guesses about what may be wrong arrive on your browser display. to get your variables to print, drop the following subroutines into your script somewhere: sub VV { return unless ($D); printf ( "the value of '%s' is: %s (%s) sub &%s(), line %d\n", @_, (caller (1))[3,2] ); } sub EE { return unless ($T); printf ( qq(entering &%s(), line %d: args = "%s"\n), (caller (1))[3,2], join (', ', @_) ); } sub XX { return unless ($T); printf ( qq(leaving &%s(), line %d (%s)\n), (caller (1))[3,2], @_ ); } set the two flags at the beginning of the regular script: $D = 1; $T = 1; then call the routines in the following manner: sub some_func { &EE (@_); for $i (0..9) { &VV ('i', $i, "checking the loop"); print "i = $i\n"; } &XX ('normal exit'); } &some_func ('this', 'that', 'other'); the flags allow you to switch the variable debugging and flow tracing on and off separately. i personally prefer to 'outdent' all my debugging routine calls, because it emphasizes the fact that they're not part of the regular code. it also makes them easier to spot when you want to go back through and check the code. i use these routines all the time, and frankly, prefer them to the built-in debugger.