判断当前循环迭代是否为最后一次

To determine whether the current loop iteration is the last one or not

我们如何知道并确定当前循环点是否是最后一个循环点(因为它在 Perl 中简单地完成,因为有 \ref.operator see on)?

编辑更正link: https://perlmonks.org/?node_id=11140741

请帮忙指出解决方法。谢谢

如果你想在循环的最后一次迭代中做某事,为什么不使用 LAST 移相器?

for ^5 {
    FIRST say "$_ is the first";
    LAST say "$_ was the last";
    .say;
}

输出:

0 is the first
0
1
2
3
4
4 was the last