交替做这样的事情perl:`(10 ... 0)` [英] Alternate for making such a thing work in perl : `for(10...0)`
本文介绍了交替做这样的事情perl:`(10 ... 0)`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这在perl中不起作用: for(10 ... 0)它实质上不会循环一次,因为它会检查
10> 0
。
This doesn't work in perl : for(10...0)
It essentially doesn't loop even once, because it checks that 10>0
initially.
为循环创建递减的迭代的另一种简写形式
推荐答案
for (reverse 0 .. 10) {
say $_;
}
使用 reverse
function 。
Use the reverse
function.
这强制范围评估列表,所以这比使用更多的内存比没有 reverse
。
Unfortunately, this forces evaluation of the range to a list, so this uses more memory than the loop without reverse
.
这篇关于交替做这样的事情perl:`(10 ... 0)`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文