Reputation: 54223
Perl newbie here.
The Perl documentation for map
shows two usage forms:
map BLOCK LIST
map EXPR, LIST
I don't fully understand the semantic difference between the two. When should I choose one form over the other? Does the EXPR
form limit me to one expression while the BLOCK
form allows me to have multiple statements (more complex logic)?
Upvotes: 2
Views: 579
Reputation: 386541
The only difference other than the syntax is the scope introduced by the curlies. For example,
>perl -E"use strict; map my $x = $_, 1,2,3,4; say $x"
>perl -E"use strict; map { my $x = $_ } 1,2,3,4; say $x"
Global symbol "$x" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
Upvotes: 4