Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

phpmyadmin fehler rechte unerlaubte mischung, WWWXXXApc, lilo trying to map files from unnamed device 0x0000", Wwwxxxapc, CAM::PDF::Renderer::TextF Fragen, adodb.recordset error '800a0cc1', php save mails as eml, WWWXXXAPC, sqlexpress database file auto-creation error, sqlexpress database file auto-creation error

Links

XODOX
Impressum
Datenschutz

#1: Why perlcritic complains?

Posted on 2011-09-30 12:23:05 by 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/

Report this message

#2: Re: Why perlcritic complains?

Posted on 2011-09-30 14:56:29 by 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/

Report this message

#3: Re: Why perlcritic complains?

Posted on 2011-09-30 15:06:32 by 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/

Report this message

#4: Re: Why perlcritic complains?

Posted on 2011-09-30 19:19:03 by 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/

Report this message

#5: Re: Why perlcritic complains?

Posted on 2011-09-30 19:34:46 by 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/

Report this message

#6: Re: Why perlcritic complains?

Posted on 2011-09-30 20:14:06 by 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/

Report this message

#7: Re: Why perlcritic complains?

Posted on 2011-09-30 20:26:50 by 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/

Report this message

#8: Re: Why perlcritic complains?

Posted on 2011-10-01 13:57:50 by 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/

Report this message