Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 37905
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: amir.aharoni [...] mail.huji.ac.il
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.090
Fixed in: (no value)



Subject: do BLOCK while shouldn't be prohibited at ControlStructures::ProhibitPostfixControls
The construct my $count = 3; do { print "hello $count\n"; # always runs the first time } while (--$count); is a special case where a programmer always wants the BLOCK to run once before the condition is evaluated. The alternative is to write the BLOCK twice. (Correct me if i'm wrong.) It is different from the simple postfix while such as this: my $count = 3; print "hello\n" while (--$count); In the second case the postfix while indeed makes the code less readable. PBP doesn't mention the do { } while block. So, postfix while after a do { } block should be allowed.
Subject: postfix.pl
#!/usr/local/bin/perl use strict; use warnings; my $countdown = 3; do { print "hello $countdown\n"; } while (--$countdown);
There is a separate policy "Don't use do-while loops" on PBP page 123. But this is an argument in favour of exempting do-while from this policy, since it's already covered by another.
From: amir.aharoni [...] gmail.com
On Thu Jul 24 10:11:53 2008, EDAVIS wrote: Show quoted text
> There is a separate policy "Don't use do-while loops" on PBP page 123. > But this is an argument in favour of exempting do-while from this > policy, since it's already covered by another.
Missed it! I won't argue with PBP then. You may close this.
Subject: Re: [rt.cpan.org #37905] do BLOCK while shouldn't be prohibited at ControlStructures::ProhibitPostfixControls
Date: Thu, 24 Jul 2008 08:10:31 -0700
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <perl [...] galumph.com>
EDAVIS via RT wrote: Show quoted text
> There is a separate policy "Don't use do-while loops" on PBP page 123. > But this is an argument in favour of exempting do-while from this > policy, since it's already covered by another.
Actually, there isn't. (unless I've missed something.) However, this policy should be changed to look for this situation and change its explanation where this is found. Added to the todo list.
From: amir.aharoni [...] gmail.com
On Thu Jul 24 11:11:20 2008, clonezone wrote: Show quoted text
> EDAVIS via RT wrote:
> > There is a separate policy "Don't use do-while loops" on PBP page
> 123.
> > But this is an argument in favour of exempting do-while from this > > policy, since it's already covered by another.
> > Actually, there isn't. (unless I've missed something.)
It's a best practice in the book, not in P::C. I checked it, it's on page 123 indeed, and it's rather convincing.