Lint-like program for Perl?

末鹿安然 提交于 2019-12-03 15:00:50

问题


I'm looking for a lint for Perl, something that would catch dead code and other potential problems. Any suggestions?

I have

use strict;
use warnings;

already but I'd like to have more.


回答1:


Perl doesn't have a direct equivalent to lint. A large part of the reason for that is that Perl doesn't provide quite as many ways to hang yourself as C does. The basic version of "lint" for Perl is this:

perl -Mstrict [-Mdiagnostics] -cw <file>

This causes perl to compile (but not run) the specified file with strictures and warnings turned on. You can use diagnostics if you want more verbose messages or leave it out if the terse ones are enough for you.

If you want something more try using Perl::Critic, but be aware that this isn't really lint, either. lint primarily concerns itself with errors (e.g. things that would prevent compilation, trigger runtime errors, be non-portable, rely on undefined behavior, etc.). Perl::Critic is more focused on enforcement of coding standards. While there is some overlap they're very different things.




回答2:


Perl::Critic is your friend. I use Test::Perl::Critic and build it into my code's author tests




回答3:


Use B::Lint. You can use it on command line by calling O module with Lint as argument, e.g.:

you@there:~/sandbox$ perl -MO=Lint Some.pm 
Implicit scalar context for array in logical and (&&) at Some.pm line 121
Implicit scalar context for array in conditional expression at Some.pm line 49
Implicit scalar context for array in logical and (&&) at Some.pm line 132
Some.pm syntax OK



回答4:


In addition to Perl::Critic you might want to look at the newer Perl::Lint.



来源:https://stackoverflow.com/questions/6835218/lint-like-program-for-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!