in reply to Does redo create a new dynamic scope?

Saying next or redo skips the execution of - what? the current block? Right; but that block cannot be the outer block; that would be last. So these OPs need something to skip, and that's why an implicit block (and scope) is created inside a block in which next or redo are found.

<update>

In your example (label added)

LOOP: for( my $i = 1; $i =~ m/\d/, my $j = $i**2; $i++) { print "I saw [$i] and [$j]\n"; redo LOOP if $& == 5; last if $i == 10; }

the redo goes straight to the LOOP label, so the scope of the loop is re-entered, and my-variables get reset (match variables too), as expected. But the execution of the "loop control block" conditional is skipped, which is why $j is undef after the redo.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Does redo create a new dynamic scope? (yes)
by wazoox (Prior) on Jul 19, 2007 at 13:52 UTC
    But the execution of the "loop control block" conditional is skipped, which is why $j is undef after the redo.

    This definitely makes sense. I don't know about other readers of this thread but you saved my sanity with this one :)

      I don't know about my sanity, but this has certainly been one of the most interesting threads of late. It's interesting to see some of Perl elites digging under the hood to figure out some perplexing behavior. One of the reason I read this site is to learn tidbits like this.
Re^2: Does redo create a new dynamic scope? (yes)
by Argel (Prior) on Jul 19, 2007 at 20:34 UTC
    Score one for Perl Best Practices (pg 129):

    Label every loop that is exited explicitly, and use the label with every next, last, or redo.

    Ironic given that we were debating the appropriateness of the title "Perl Best Practices" a while back in this thread: Re: Returning undef: The point I would like Damian to reconsider.