Why perlcritic complains?
Why perlcritic complains?
am 30.09.2011 12:23:05 von Lubos Kolouch
Hello,
I cannot understand, why perlcritic complains about this script:
use strict;
use warnings;
use 5.012;
open my $file, '<', 'file.txt';
my @array;
while (<$file>) {
chomp;
my $value =3D $_*2;
say "OK";
push @array, $value;
}
close $file;
$ perlcritic -4 t16.pl=20
Close filehandles as soon as possible after opening them at line 25,=20
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?
Thank you
Lubos
PS. The script does not do anything terribly useful, I created it to=20
demonstrate the perlcritic behaviour...
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Why perlcritic complains?
am 30.09.2011 14:56:29 von Shawn H Corey
On 11-09-30 06:23 AM, Lubos Kolouch wrote:
> use strict;
> use warnings;
> use 5.012;
>
> open my $file, '<', 'file.txt';
# always check open
open my $file, '<', 'file.txt' or die "could not open file.txt: $!\n";
> my @array;
>
> while (<$file>) {
> chomp;
>
> my $value = $_*2;
> say "OK";
> push @array, $value;
> }
> close $file;
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
"Make something worthwhile." -- Dear Hunter
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Why perlcritic complains?
am 30.09.2011 15:06:32 von Paul Johnson
On Fri, Sep 30, 2011 at 10:23:05AM +0000, Lubos Kolouch wrote:
> Is it a bug in perlcritic?
I don't use perlcritic, but it seems like a bug to me.
Are you using the latest version of perlcritic? If so, I would suggest
submitting this as a bug report if someone has not already done so.
https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Criti c
--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Why perlcritic complains?
am 30.09.2011 19:19:03 von Lubos Kolouch
Paul Johnson, Fri, 30 Sep 2011 15:06:32 +0200:
> On Fri, Sep 30, 2011 at 10:23:05AM +0000, Lubos Kolouch wrote:
>=20
>> Is it a bug in perlcritic?
>=20
> I don't use perlcritic, but it seems like a bug to me.
>=20
> Are you using the latest version of perlcritic? If so, I would suggest
> submitting this as a bug report if someone has not already done so.
>=20
> https://rt.cpan.org/Public/Dist/Display.html?Name=3DPerl-Cri tic
>=20
> --
> Paul Johnson - paul@pjcj.net http://www.pjcj.net
Thanks, I will do that.
P.S. I know I should check the return value from the open, I just
tried to keep the sample as simple as possible...
Lubos
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Why perlcritic complains?
am 30.09.2011 19:34:46 von Lubos Kolouch
Lubos Kolouch, Fri, 30 Sep 2011 17:19:03 +0000:
> Paul Johnson, Fri, 30 Sep 2011 15:06:32 +0200:
>=20
>> On Fri, Sep 30, 2011 at 10:23:05AM +0000, Lubos Kolouch wrote:
>>=20
>>> Is it a bug in perlcritic?
>>=20
>> I don't use perlcritic, but it seems like a bug to me.
>>=20
>> Are you using the latest version of perlcritic? If so, I would sugges=
t
>> submitting this as a bug report if someone has not already done so.
>>=20
>> https://rt.cpan.org/Public/Dist/Display.html?Name=3DPerl-Cri tic
>>=20
>> --
>> Paul Johnson - paul@pjcj.net http://www.pjcj.net
>=20
> Thanks, I will do that.
>=20
> P.S. I know I should check the return value from the open, I just tried
> to keep the sample as simple as possible...
>=20
> Lubos
Hello again,
So it seems perlcritic is perhaps right - when I swap the lines=20
my @array; and open ..., it does not complain anymore.
So I guess it is in facts correct behaviour of perlcritic :)
Thank you for your help anyway...
Lubos
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Why perlcritic complains?
am 30.09.2011 20:14:06 von Rob Dixon
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-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Why perlcritic complains?
am 30.09.2011 20:26:50 von Paul Johnson
On Fri, Sep 30, 2011 at 05:34:46PM +0000, Lubos Kolouch wrote:
> Hello again,
>
> So it seems perlcritic is perhaps right - when I swap the lines
> my @array; and open ..., it does not complain anymore.
>
> So I guess it is in facts correct behaviour of perlcritic :)
Something about this didn't smell right to me, so I have investigated
further.
The policy of which you are running afoul is InputOutput::RequireBriefOpen.
It seems that all this policy is checking is that your close() comes within
a certain number of lines of your open(), the default being 9. This is the
reason you didn't get a criticism when you deleted the say(), or when you
changed the order of the lines. You could equally as well have deleted one
of the blank lines.
I see little value in this policy, but that applies to a number of other
policies and, as I mentioned, i don't use perlcritic anyway. If you want
to keep using this policy then I suppose you should either adhere to it, or
tweak the configuration until you are happy with it.
--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Why perlcritic complains?
am 01.10.2011 13:57:50 von Lubos Kolouch
Paul Johnson, Fri, 30 Sep 2011 20:26:50 +0200:
> On Fri, Sep 30, 2011 at 05:34:46PM +0000, Lubos Kolouch wrote:
>=20
>> Hello again,
>>=20
>> So it seems perlcritic is perhaps right - when I swap the lines my
>> @array; and open ..., it does not complain anymore.
>>=20
>> So I guess it is in facts correct behaviour of perlcritic :)
>=20
> Something about this didn't smell right to me, so I have investigated
> further.
>=20
> The policy of which you are running afoul is
> InputOutput::RequireBriefOpen.
> It seems that all this policy is checking is that your close() comes
> within a certain number of lines of your open(), the default being 9.=20
> This is the reason you didn't get a criticism when you deleted the
> say(), or when you changed the order of the lines. You could equally a=
s
> well have deleted one of the blank lines.
>=20
> I see little value in this policy, but that applies to a number of othe=
r
> policies and, as I mentioned, i don't use perlcritic anyway. If you
> want to keep using this policy then I suppose you should either adhere
> to it, or tweak the configuration until you are happy with it.
>=20
> --
> Paul Johnson - paul@pjcj.net http://www.pjcj.net
Paul,
All clear, you are right
Thanks
Lubos
--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/