Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- my $name = 'Jacob';
- {
- my $name = 'Edward';
- say $name =;
- }
- say $name;
- # This would print Edward, then Jacob.
- # This is because the lexical in the nested scope hides the lexical in the outer scope.
- # More complex example.
- # Here, the lexical variable is used as the iterator variable of a for loop.
- # Its declaration occurs outside the bock, but its scope is that within the loop block:
- my $cat = 'Brad';
- for my $cat (qw(Jack Daisy Petunia Tuxedo Choco)) {
- say "Inner cat is $cat";
- }
- say "Outer cat is $cat";
Add Comment
Please, Sign In to add comment