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

$ perl -wle'use strict; map +(my $x = $_), 2; print $x' Use of uninitialized value in print at -e line 1.
It seems a run-time scope is created for map EXPR,.

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

$ perl -wle'use strict; my $x = $_ for 2; print $x' Use of uninitialized value $x in print at -e line 1.

Braces or file boundaries are the only things that can create scope.

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

    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".

      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,.