Есть такой код:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
my $hash = {
key1 => 'value1',
key2 => 'value2',
key3 => 'value3',
};
my @options = map { "--$_" => $hash->{$_} } # line 13
grep { defined $hash->{$_} } # line 14
qw(key1 key4); # line 15
print Dumper(\@options);
Perl 5.22 выдает такое:
syntax error at ./test.pl line 14, near "grep"
Global symbol "@options" requires explicit package name (did you forget to declare "my @options"?) at ./test.pl line 17.
Execution of ./test.pl aborted due to compilation errors.
Perl 5.10:
Not enough arguments for map at ./test.pl line 14, near "grep"
syntax error at ./test.pl line 14, near "grep"
Execution of ./test.pl aborted due to compilation errors.
«Исправление» вот такое:
-my @options = map { "--$_" => $hash->{$_} } # line 13
+my @options = map { ("--$_") => $hash->{$_} } # line 13
Внимание вопрос: почему не работает первый вариант кода? Что интерпретатору не нравится в кавычках?