gpt4 book ai didi

perl - `my $foo` 和 `my ($foo)` 有什么区别?

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

有什么区别

my $foo

my ($foo)

最佳答案

my $amy ($a) 没有区别。

但是,两者之间有天壤之别

my $a = some_function();

my ($a) = some_function();

第一个示例在标量上下文中调用 some_function。第二个在列表上下文中调用它。

如果您的函数如下所示:

sub some_function {
return ( 'Larry', 'Moe', 'Curly' );
}

那么你的结果将是:

my $a = some_function();  # $a gets "Curly", the last element in the list.
my ($a) = some_function(); # $a gets "Larry" and the other two values are discarded.

关于perl - `my $foo` 和 `my ($foo)` 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28327905/

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