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

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.

Replies are listed 'Best First'.
Re^6: syntax of map operator
by ikegami (Patriarch) on Jan 24, 2010 at 21:56 UTC

    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.

        Yes you are allowed to use my there, it is not a syntax error!

        No, the behaviour of using a lexical that whose declaration is conditionally executed 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."