這是我不明白的東西。爲什麼Perl函數「map」給出錯誤「Map not enough arguments」
該腳本正常工作(注意在地圖載體作用的串聯):
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %aa = map { 'a' . '' => 1 } (1..3);
print Dumper \%aa;
__END__
output:
$VAR1 = {
'a' => 1
};
但無連接地圖不起作用。這裏是我期望工作的腳本,但它不是:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %aa = map { 'a' => 1 } (1..3);
print Dumper \%aa;
__END__
output:
Not enough arguments for map at e.pl line 7, near "} ("
syntax error at e.pl line 7, near "} ("
Global symbol "%aa" requires explicit package name at e.pl line 9.
Execution of e.pl aborted due to compilation errors.
你能解釋這種行爲嗎?
沒什麼用你的答案來做,但是基於編程語言的猜測語法並不能使我成爲好設計。 – antred