I'm posting a second follow-up to your thread, because I think that one important use of redo hasn't gotten proper attention (including in my previous followup).

Some of the examples listed are using redo in a bare block, which essentially creates a loop whos termination is going to rely on logic within the block placing a call to last.

But remember also that redo will repeat the current iteration of a loop, without going through the loop's conditional or next-iteration stage first. Consider the following example:

my @array = qw/this that those these/; foreach my $word ( @array ) { print $word, "\t"; redo if $word =~ m/that/; }

The output will be "this    that    that    that...." because redo repeats the current iteration without moving on to the next iterant (which would be 'those').

This can be useful if you're trying to keep your loop working on the same iteration until some other condition is met. Perhaps you are blocking, or maybe you're waiting for a mouse click, etc.


Dave


In reply to Re: Useful uses of redo? by davido
in thread Useful uses of redo? by kvale

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.