I just tried the following code...which is a variation on what you show.
#!/user/bin/perl use warnings; use strict; my $i = 10; print "$i\n"; foreach $i (0..5){ print "$i\n"; } # end foreach $i loop print "$i\n"; exit(0);
It prints the following:
10 0 1 2 3 4 5 10
This is exactly what I believe the Camel says it should do since the loop variable is, if I recall correctly, always created anew as a lexical whose scope is the subsequent loop block (even though it appears to be created before the loop block). The output above seems to confirm that.
I, like BrowserUk, however am a bit perplexed by the inability to use the $i[0] construct as the loop variable.
Is it because the $i[0] implies a list structure which does not get created (via, for example, autovivification...spelling?)?
In reply to Re^6: Hard syntax error or disambiguable parsing?
by ack
in thread Hard syntax error or disambiguable parsing?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |