in reply to Syntax error with nested for loop

Hello tel2,

In the first snippet, the inner foreach loop is followed by a code block. But in the second and third snippets, the for is actually a statement modifier, which, as a matter of Perl syntax, has to use $_ as the loop variable. So in the third snippet, the attempt to use $b in place of $_ results in a syntax error. See perlsyn#Statement-Modifiers.

Update: Made correction re the second snippet, in which the for is also a statement modifier; also improved wording.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Syntax error with nested for loop
by tel2 (Pilgrim) on Sep 22, 2015 at 20:59 UTC
    Thanks very much for that lightning fast and well explained answer, Athanasius!