The disadvantage of that idiom is that the scope of $line must extend outside the block where is it used. Declaring $line inside the block results in a syntax error
use strict;
do {
my $line = <STDIN>;
...
} until $line eq ".\n"; # Syntax error
__END__
Global symbol "$line" requires explicit package name
unlike a while(condition) {} the condition is not in the same scope as the block. It can be written as
use strict;
INPUT:
while ( my $line = <STDIN> ) {
last INPUT if $line eq ".\n";
...
}
which will restrict $line to the while block
Update: Code updated |