in reply to Re^3: Scope and references
in thread Scope and references
Actually, for creates two lexical scopes. One for the entire statement, and one of the block body.
You've already demonstrated the second. Here's a demonstration of the first:
>perl -e"use strict; for (my @x) { } @x" Global symbol "@x" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.
I don't think your example serves to prove your statement. Here's what I think is a better example:
use strict; use warnings; use 5.010; for (my @x) { my @x; } my @y; my @y; #line 10 --output:-- "my" variable @y masks earlier declaration in same scope at perl.pl li +ne 10.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Scope and references
by ikegami (Patriarch) on Jun 20, 2011 at 17:03 UTC |