in reply to Re: do until loop breaks before meeting the condition
in thread do until loop breaks before meeting the condition

ehm ... he's using goto as loop control, last, next and redo are not much different.

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! :)

update

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

    To: Lanx,

    Thanks, I was not even aware of: last, next and redo.

    Hmmm based on second look your solution looks simple and I ques better than mine. I think I will follow it.

    Again thank you for your time and all this information that you shared.

    Seeking for Perl wisdom...on the process...not there...yet!
Re^3: do until loop breaks before meeting the condition
by Laurent_R (Canon) on Jun 09, 2014 at 06:22 UTC
    Well, I am not an anti-goto fanatic, the comment on gotos was just one out of 3 comments. I still think it is much better to use regular loop control statements (last, next, etc.), and it is most of the time best to avoid gotos altogether (except for the special goto &name construct).