reverse 不在列表上下文中隐式使用 $_,这是一个错误吗? [英] reverse doesn't use $_ implicitly in list context, is this a bug?
本文介绍了reverse 不在列表上下文中隐式使用 $_,这是一个错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@array = reverse;和@array = 反向 $_;
两者都不一样.@array = reverse
不隐式使用 $_
.我们必须显式声明 $_
.这是一个非常奇怪的情况,默认情况下没有使用 $_
.是bug吗?
解决方案
据我了解 反向文档,反向
适用于数组,所以它应该使用@_
而不是标量$_
?>
文档说在标量上下文中不带参数使用,reverse()
反转$_
."[强调]
$_ = "dlrow ,olleH";反印;# 无输出,列出上下文打印标量反转;# 你好,世界
@array = reverse;
and
@array = reverse $_;
Both are different. @array = reverse
doesn't use $_
implicitly. We have to declare $_
explicitly. It's a very strange case where $_
is not being used by default. Is it a bug?
解决方案
As far as I understand from the reverse documentation, reverse
works on arrays, and so it should use @_
rather than the scalar $_
?
The documentation says "Used without arguments in scalar context, reverse()
reverses $_
." [Emphasis added]
$_ = "dlrow ,olleH";
print reverse; # No output, list context
print scalar reverse; # Hello, world
这篇关于reverse 不在列表上下文中隐式使用 $_,这是一个错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文