gpt4 book ai didi

perl - 为什么 `sort List::Util::uniq(BAR, BAZ);` 与 `sort &List::Util::uniq(BAR, BAZ);` 不同

转载 作者:行者123 更新时间:2023-12-03 07:49:49 24 4
gpt4 key购买 nike

我知道 & 会禁用原型(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 listreturned from a function. If you want to sort the list returned bythe 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 comparisonroutine "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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com