in reply to Re: do until loop breaks before meeting the condition
in thread do until loop breaks before meeting the condition
Than you don't print the $msg before first run like he did.
Considering "cleanest" and "DRYest" flow control , I'd rather try this
> perl $max_length=5; OUTER: { print "Input max is $max_length!!!\n"; while (1) { chomp( $input = <STDIN> ); last OUTER if lc( $input ) eq "end"; redo OUTER if length( $input ) > $max_length; print "- $input is OK\n"; } } __END__ Input max is 5!!! 1 - 1 is OK 12345 - 12345 is OK 123456 Input max is 5!!! 123 - 123 is OK end >
YMMV! :)
please note that the more verbose
OUTER: while(1) { ...
works equally well and might be less surprising for some maintainers. :)
Cheers Rolf
(addicted to the Perl Programming Language)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: do until loop breaks before meeting the condition
by thanos1983 (Parson) on Jun 08, 2014 at 18:50 UTC | |
|
Re^3: do until loop breaks before meeting the condition
by Laurent_R (Canon) on Jun 09, 2014 at 06:22 UTC |