我認爲none
從List::MoreUtils
子程序不起作用的描述。根據文件,Is List :: MoreUtils :: none buggy?
none BLOCK LIST邏輯上否定任何。如果 返回真實值LIST中的項目不符合通過BLOCK,或LIST 爲空給出的標準。反過來
設置$ _在列表中的每個項目現在,嘗試:
use strict;
use warnings;
use 5.012;
use List::MoreUtils qw(none);
my @arr = (1, 2, 3);
if (none { $_ == 5 } @arr) {
say "none of the elements in arr equals 5";
}
else {
say "some element in arr equals 5";
}
工程確定,但有一個空(my @arr =();
或者乾脆my @arr;
)取代@arr
,你會得到一個錯誤的答案。
發生了什麼事?
更新:我有List :: MoreUtils ver 0.22。更新到最新,似乎還可以。雖然很奇怪!
0.22版本之間實現改變和最新的 - 看到我的回答 – Zaid