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

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.

Replies are listed 'Best First'.
Re^8: syntax of map operator
by ikegami (Patriarch) on Jan 25, 2010 at 02:50 UTC

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