in reply to Re^3: syntax of map operator
in thread syntax of map operator

Incorrect. What is happening is the same thing that happens when you do that with a foreach statement modifier:

That should read "Correct, just like with a foreach statement modifier".

Replies are listed 'Best First'.
Re^5: syntax of map operator
by jwkrahn (Abbot) on Jan 24, 2010 at 20:10 UTC

    Yes, but, it's not scope, it's undefined behaviour.    From perlsyn:

    NOTE: The behaviour of a "my" statement modified with a statement modifier conditional or loop construct (e.g. "my $x if ...") is undefined. The value of the "my" variable may be "undef", any previously assigned value, or possibly anything else. Don’t rely on it. Future versions of perl might do something different from the version of perl you try it out on. Here be dragons.

    Emphasis added.

      Yes, but, it's not scope, it's undefined behaviour.

      You say that as if they're mutually exclusive. Yes, you're not allowed to use my there. And whether you use my or not, map creates a scope for both map BLOCK and map EXPR,.

        Yes you are allowed to use my there, it is not a syntax error!    And using it there produces a variable that is in the same scope as map is in.    It is just that the value of the variable created is not defined by the Perl language.    Compare the different error messages:

        $ perl -wle'use strict; map +(my $x = $_), 2; print $x' Use of uninitialized value $x in print at -e line 1. $ perl -wle'use strict; { map +(my $x = $_), 2; } print $x' Global symbol "$x" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.