Questions tagged [perl-critic]

Perl::Critic is an extensible framework for creating and applying coding standards to Perl source code. Essentially, it is a static source code analysis engine. Perl::Critic is distributed with a number of Perl::Critic::Policy modules that attempt to enforce various coding guidelines.

Perl module on CPAN: Perl::Critic

perlcritic: Command-line interface to critique Perl source.

Wikipedia link

61 questions
3
votes
3 answers

Perlcritic: How can I resolve '^Magic variable "$ENV" should be assigned as "local"'?

I am writing a perl script that needs to set a number of environment variables before calling an external program. My code has the form $ENV{'VAR1'} = "value1"; $ENV{'VAR2'} = "value2"; When running this through perlcritic, I get a severity…
alisea
  • 362
  • 1
  • 8
3
votes
2 answers

Why am I *not* getting this warning: "variable masks earlier declaration"?

Here's my entire script, crafted to include two variable with the same name, one of which is masking the other: #!/usr/bin/env perl use strict; use warnings; my $hi = "First hi"; print "$hi\n"; { my $hi = "Second hi"; print…
Flimm
  • 136,138
  • 45
  • 251
  • 267
3
votes
2 answers

Critiquing PHP-code / PerlCritic for PHP?

I'm looking for an equivalent of PerlCritic for PHP. PerlCritc is a static source code analyzer that qritiques code and warns about everything from unused variables, to unsafe ways to handle data to almost anything. Is there such a thing for PHP…
jeekl
  • 372
  • 3
  • 9
3
votes
2 answers

perl IPC:Open3 minimal to pass perlcritic?

I am reading the perlcritic documentation to avoid backticks and use IPC::Open3 here: http://perl-critic.stacka.to/pod/Perl/Critic/Policy/InputOutput/ProhibitBacktickOperators.html I am trying to find the least verbose option that will work and…
719016
  • 9,922
  • 20
  • 85
  • 158
3
votes
1 answer

perlcritic with additional profiles

Is it possible to "add" another profile to perlcritic default profile, or run perlcritic with multiple profiles? I do not want to skip/replace the default profile. I need to add an additional profile to it. I know I could export current profile and…
farzad
  • 8,775
  • 6
  • 32
  • 41
3
votes
1 answer

B::Lint and Perl::Critic for static code analysis

I need to implement lint and Perl::Critic for static code analysis in Perl. I have found B::Lint module for lint in Perl. Is it really required to use both the modules for static code analysis? If yes, then how these two modules work together?
mypearl
  • 61
  • 5
2
votes
3 answers

How can I sort one key ascending, another descending without using $b (comparison) $a in Perl?

In Perl, I can do: my @unit_indices = sort { $units{$b}[0] <=> $units{$a}[0] or $a cmp $b } keys %units; which sorts by one field (array element) descending and the other (hash key) ascending, but causes perlcritic to…
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
2
votes
2 answers

Perl: What is the preferred way of evaluating expressions besides eval?

I am attempting to use arithmetic to evaluate the a function, which is written as a string: #!/usr/bin/env perl use strict; use warnings FATAL => 'all'; use feature 'say'; use autodie ':default'; my $str = '0.203580063041053 * $x +…
con
  • 5,767
  • 8
  • 33
  • 62
2
votes
2 answers

Should a subroutine always return explicitly?

If perlcritic says "having no returns in a sub is wrong", what is the alternative if they really aren't needed? I've developed two apparently bad habits: I explicitly assign variables to the '$main::' namespace. I then play with those variables in…
BIGMOOSE
  • 146
  • 7
2
votes
2 answers

perl using bless self in script and PerlCritic

I am used to using $self for OO Perl even when I am just writing self-contained scripts without naming my package at all. For example, my script.pl would start like this: use strict; use warnings; my $self = bless…
719016
  • 9,922
  • 20
  • 85
  • 158
2
votes
2 answers

How do I get Perl::Critic to work with E.P.I.C and eclipse?

I'm running eclipse Galileo with EPIC 0.5.46 and ActiveState ActivePerl 5.10.0, on WinXP SP3. I just downloaded Perl::Critic using the package manager, and integrated it to eclipse using the appropriate Properties page. I can run Perl::Critic just…
O. Jones
  • 103,626
  • 17
  • 118
  • 172
2
votes
3 answers

Make Perl warn me about missing unused functions

perl -wle 'if (0) {no_such_func()}' The above runs without errors, despite the -w, because no_such_func() is never called. How do I make Perl check all functions/modules I reference, even ones I don't use? In a more realistic case, some…
user354134
2
votes
1 answer

Perlcritic Thinks Hashes are Statements Separated by Commas

I'm getting a perlcritic violation that makes no sense for blocks of code like the following: $object->insert( { %defaults, name => 'TEST', line => 1, keywords => 'TEST OBJECT', %overrides …
Jacob Rose
  • 430
  • 4
  • 6
2
votes
2 answers

Do I need to trap errors in my calls to Win32::OLE->LastError?

[EDIT] - with the benefit of hindsight, this question was misdirected. I have not deleted it because it is a good example of the incorrect use of eval and correct criticism by Perl::Critic. Perl Critic raises the following criticism for the code…
heferav
  • 759
  • 5
  • 11
2
votes
8 answers

How can I avoid Perl::Critic warnings when I process a multi-line string with a filehandle?

Does anyone have a solution to the task of processing a multi-line string one line at a time, other than the string-as-a-filehandle solution shown below? my $multiline_string = "line one\nline two\nline three\nline four"; my $filehandle; open(…
Kurt W. Leucht
  • 4,725
  • 8
  • 33
  • 45