in reply to debugging
I've noticed that a lot of my debugging time is spent debugging the wrong code, i.e the error is somewhere else than I think. This is because you narrow down to quickly on a perceived problem, and because errors get layered on top of each other, so that the cause of the error is actually some minutes, or even days old. One remedy to this is to use
every minute or so, so that you catch little syntax errors when they are done. If you're in an error-prone mode otherwise little errors will be layered on top of each other.perl -c your_script.pl
A graphical debugger like ptkdb is really good for those (like me:-) who have problem keeping structures in (the brain's) memory. Graphical debugger means see-and-act instead of remember-and-type.
While programming, write little test scripts to test how certain things in perl work, before you rely on them in your scripts. Save the test scripts with a comment on what happened.
Use print statements to check what is actually happening in your script. Use Data::Dumper (in the core distribution) to print out complex structures. Here is a module I use. It is a hack but it seems to do what I want:
package jmdebug; # Debugging module # # # PURPOSE: to provide debugging information concerning methods # # CALLING FORMAT: # jmdebug::output("Description text",$scalarvariable_or_complex_refere +nce); # Put the above line with modification in e.g. any metod calls you wan +t to keep tabs on # In order to include several variables, do something like this: # jmdebug::output("Description text",\[$var1,$var2,\@array1]); # # BEHAVIOUR:checks to see if global var $debug is true, tries to gathe +r information in a subroutine context # which is done with the caller(1) syntax. If that does not work does +a plain caller(0) function call # Tries to pretty-print results use Data::Dumper; # used to display data structures sub output { if ($main::debug){ my ($pack, $filename, $line, $sub, $arg, $context, $dummy, $subnam +e); ($pack, $filename, $line, $sub, $arg, $context) = caller(1) or ($ +pack, $filename, $line, $dummy, $arg, $context) = caller(0); $text = shift @_; my $datastructure = shift @_; $datastructure = Dumper($datastructure); $datastructure =~ s§^\$VAR1 \= §§; $subname = $sub; $subname =~ s§^.*\:\:§§; my ($pre, $post); if ($main::debug_html) { $pre = "<PRE>"; $post = "</PRE>"; } print (qq§ $pre _____ / \\_________________________________________________ | | $subname : | ** $text ** | package: $pack | line: $line | in subroutine: $sub variable contains: $datastructure | |__________________________________________________________ $post§);} } 1;
Finally, write test scripts to give your subs or methods a run-through with different parameters and scenarios.
/jeorgen
|
|---|