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, |
In reply to Re: Syntax error with nested for loop
by Athanasius
in thread Syntax error with nested for loop
by tel2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |