If the scalar variable contains a link to the code - for example:
my $double = sub { 2 * shift };
You can call the code in the same way as in Python, for example:
$double->(50);
Applying this to a map example:
my @doubles = map $double->($_), 1..10;
Or so:
my @doubles = map { $double->($_) } 1..10;
The second option is more reliable, because the block defined by the brackets {} can contain any number of Perl statements:
my @doubles = map { my $result = 2 * $_;
Fmc
source share