為什么 Perl(5.30.3 和 5.30.3 也no feature ':all'有)假設連接運算子后面的裸詞.是字串?例如:
use v5.30; # or: no feature ':all';
use strict;
use warnings;
my $k1 = 'a';
my $k2 = 'b';
print STDOUT $k1 . k2 . "\n";
列印出來ak2(ab是有意的),并且沒有提出關于此處不允許使用裸詞的例外情況。這是我的腳本中的一個錯誤,但不一定在 Perl 中。
根據perlglossary,bareword 是“在use strict 'subs'. $k2但是,由于之前定義了一個名為的標量k2,所以我認為k2它已經足夠模棱兩可了。
奇怪的是,第二個裸詞引發了例外:
use v5.30; # or: no feature ':all';
use strict;
use warnings;
my $k1 = 'a';
my $k2 = 'b';
my $k3 = 'c';
print STDOUT $k1 . k2 . k3 . "\n";
和:
Bareword "k3" not allowed while "strict subs" in use at mwe.pl line 7.
Execution of mwe.pl aborted due to compilation errors.
k3是不允許的,但是k2是。為什么?
uj5u.com熱心網友回復:
這是 5.28.0 中引入并在 5.32.0 中修復的錯誤。
新添加的(通常是多個)字串連接的編譯時優化正在跳過裸字檢查。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/443082.html
