develooper Front page | perl.perl6.language | Postings from August 2006

Curious corner cases concerning closure cloning

Thread Next
From:
Luke Palmer
Date:
August 14, 2006 09:01
Subject:
Curious corner cases concerning closure cloning
Message ID:
7ca3f0160608140901h416e80dag39bbf3f562347ba7@mail.gmail.com
What do these do?

  for 1,2 {
      my $code = {
          my $x;
          BEGIN { $x = 42 }
          $x;
      };
      say $code();
  }

  for 1,2 {
      my $code = {
          state $x;
          BEGIN { $x = 42 }  # mind you, not FIRST
          $x++;
      };
      say $code();
      say $code();
  }

  for 1,2 -> $x {
      END { say $x }
  }

Thanks,
Luke

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About