in reply to Re: What about if (my $var = foo()) { ... }
in thread What about if (my $var = foo()) { ... }

friedo,
Off hand, I can't think of any reason why this would not also be allowed in Perl 6.

In perl 5, we write:

for my $name (keys %people) { # do something with $name }

The $name lexical is implicitly scoped to the for block. This is not the case in perl 6. The way perl 6 solves this is by introducing parameters to the block so you achieve the same thing in a cleaner way (from a design perspective).

Cheers - L~R

Replies are listed 'Best First'.
Re^3: What about if (my $var = foo()) { ... }
by dsheroh (Monsignor) on Dec 29, 2007 at 16:39 UTC
    Eh? Going away? What's the corresponding Perl 6 construct and how/why is it considered to be "cleaner"?
      esper,
      See Re: What about if (my $var = foo()) { ... } for the Perl 6 construct.

      Regarding an explanation as to why formal parameters to a block are cleaner, it is similar to subs with and without signatures. If that still doesn't make any sense, I will try again when I am well rested.

      Cheers - L~R

        Thanks for the pointer. I haven't been following Perl 6 at all, so some of the new syntax I'm seeing in Synopsis 4 is still a bit unclear, but I'm pretty sure I've at least got the formal parameters bit worked out. Personally, I think it looks less obvious/consistent than the existing Perl 5 equivalent (use my to create lexicals in some situations, use -> or ^ in others) for the small benefit of eliminating implicit scopes, but I can easily see how others would disagree, given the number of complaints I've seen about subs always starting with a bunch of mys and shifts.