in reply to Re: do {$i++} until vs. $i++ until
in thread do {$i++} until vs. $i++ until
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: do {$i++} until vs. $i++ until
by ikegami (Patriarch) on Mar 25, 2008 at 08:36 UTC | |
by hipowls (Curate) on Mar 25, 2008 at 09:17 UTC |
In Section
Seekers of Perl Wisdom