Perl プロジェクトでは、通常、スクリプトのバグを修正する方法は? 誰かアイデアをください。前もって感謝します。
2 に答える
My first think is perldoc perldebug
I think it's the better place to start.
My second is : always put
use strict;
use warnings;
on the top of your script, and you can put
use diagnostics;
too, for producing a more verbose warning diagnostics
Before opening the Pandora box, takes advantage of the Perl module Data::Dumper
.
It's useful to display all (nested) data structures and objects, see (I use perlconsole
, it's nice to try some tricks):
$ perlconsole
Perl Console 0.4
Perl> my $ref = { foo => 'bar', arr => [ 1, 2, 3, [ qw/a z e r t y/ ] ] }
HASH(0x1fc25a8)
Perl> use Data::Dumper;
Perl> print Dumper $ref;
$VAR1 = {
'foo' => 'bar',
'arr' => [
1,
2,
3,
[
'a',
'z',
'e',
'r',
't',
'y'
]
]
};
1
Perl>
You will see that Perl can run a script in a debugger with
perl -d -e 42 script.pl
help said :
$ perl --help | grep -- '-d'
-d[:debugger] run program under debugger
You can "trace" it too with :
perl -d:Trace script.pl
There's a gui debugger too, it comes with Devel::ptkdb
module, example :
perl -d:ptkdb script.pl
Try
perlcritic
too, a Command-line interface to critique Perl source.
Profiling your code is also possible, see
http://metacpan.org/pod/Devel::NYTProf
http://blog.timbunce.org/2008/07/15/nytprof-v2-a-major-advance-in-perl-profilers/
perl -c <your program>
...will give you any syntax errors in a Perl script, including specific error messages which you can look up on the Internet.
Also, give yourself a chance by placing:-
use strict;
At the top of each of your Perl files. Without it, Perl will auto-vivify variables you mistype. With it in place, any variable that hasn't been declared counts as a syntax error.