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);