我知道 &
会禁用原型(prototype),但括号也不会这样做。这两个代码块有什么不同,顶部不能像底部一样运行是否有原因,
use List::Util;
use constant FOO => (1,2,3);
use constant BAR => (2,3,4,5,6);
use constant FOOBAR => sort List::Util::uniq(FOO, BAR);
use List::Util;
use constant FOO => (1,2,3);
use constant BAR => (2,3,4,5,6);
use constant FOOBAR => sort &List::Util::uniq(FOO, BAR);
最佳答案
sort很特别。
Warning: syntactical care is required when sorting the list returned from a function. If you want to sort the list returned by the function call "find_records(@key)", you can use:
my @contact = sort { $a cmp $b } find_records @key; my @contact = sort +find_records(@key); my @contact = sort &find_records(@key); my @contact = sort(find_records(@key));
If instead you want to sort the array @key with the comparison routine "find_records()" then you can use:
my @contact = sort { find_records() } @key; my @contact = sort find_records(@key); my @contact = sort(find_records @key); my @contact = sort(find_records (@key));
关于perl - 为什么 `sort List::Util::uniq(BAR, BAZ);` 与 `sort &List::Util::uniq(BAR, BAZ);` 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77533584/