On 30/09/2011 11:23, Lubos Kolouch wrote:
> Hello,
> 
> I cannot understand, why perlcritic complains about this script:

> $ perlcritic -4 t16.pl
> Close filehandles as soon as possible after opening them at line 25,
> column 1.  See page 209 of PBP.  (Severity: 4)
> 
> When I remove the "say" line, it says source OK. But anyway it is not
> possible to close the file earlier (?)
> 
> Is it a bug in perlcritic?

> $ perlcritic -4 t16.pl 
> Close filehandles as soon as possible after opening them at line 25, 
> column 1.  See page 209 of PBP.  (Severity: 4)

Hey Lubos

Please show your complete code and check your version of Perl::Critic.

I am running version 1.116 of the module, and on a severity of 'gentle'
your code gives only one warning:

  Code before strictures are enabled at line 1, column 1. See page 429 of PBP.

and adding 'use strict' as the first line, as expected, corrects this.

Winding the severity up to 'brutal' results in fourteen warnings, but
none of them are the one you describe.

My code is below.

Rob


use strict;
use warnings;

use Perl::Critic;

print $Perl::Critic::VERSION, "\n";

my $source = <<'PERL';
open my $file, '<', 'file.txt';
my @array;

while (<$file>) {
    chomp;

    my $value = $_*2;
    say "OK";
    push @array, $value;
}
close $file;
PERL

my $cr = Perl::Critic->new(-severity => 'gentle');
print $cr->critique(\$source);

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to