Guest User

Untitled

a guest
Dec 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. my $name = 'Jacob';
  2.  
  3. {
  4. my $name = 'Edward';
  5. say $name =;
  6. }
  7.  
  8. say $name;
  9.  
  10. # This would print Edward, then Jacob.
  11. # This is because the lexical in the nested scope hides the lexical in the outer scope.
  12.  
  13. # More complex example.
  14. # Here, the lexical variable is used as the iterator variable of a for loop.
  15. # Its declaration occurs outside the bock, but its scope is that within the loop block:
  16.  
  17. my $cat = 'Brad';
  18.  
  19. for my $cat (qw(Jack Daisy Petunia Tuxedo Choco)) {
  20. say "Inner cat is $cat";
  21. }
  22.  
  23. say "Outer cat is $cat";
Add Comment
Please, Sign In to add comment