逗号分隔操作如何在perl中工作?

chu*_*tar 2 perl reference bless

我目前正在学习Perl编程,并且正在运行这样的语句:

return bless { }, $type;
Run Code Online (Sandbox Code Playgroud)

I know what return bless { }; would do, and I also know what return $type; would do, but how does separating them by a comma affect the statement, and does it work the same way for all unary operators?

cjm*_*cjm 5

bless不是一元运算符,所以会发生的是$type传递给bless它(它被用作类的名称来保护hashref).

返回的唯一特殊之处是右侧的表达式可能会在list,scalar或void上下文中进行计算,具体取决于调用子例程的上下文.

逗号操作符不是在解释什么不同return说法那将是比其他任何地方(除了你不能告诉它是否是列表或标量上下文通过查看return语句).