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
unlike a while(condition) {} the condition is not in the same scope as the block. It can be written asuse strict; do { my $line = <STDIN>; ... } until $line eq ".\n"; # Syntax error __END__ Global symbol "$line" requires explicit package name
which will restrict $line to the while blockuse strict; INPUT: while ( my $line = <STDIN> ) { last INPUT if $line eq ".\n"; ... }
Update: Code updated
In reply to Re^2: do {$i++} until vs. $i++ until
by hipowls
in thread do {$i++} until vs. $i++ until
by jethro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |