arrays - Perl 中是否有任何函数可以移动数组元素而不删除它们?

我有一个数组,比如 @array1 = qw(abc def ghi jkl)

现在,我想以元素逐一移动的方式使用此数组,但这种移动实际上是发生的,而不是在数组中。

例如,“shift”将移动元素并将它们从数组中移除。但是,我不想删除这些元素。

短代码片段:

while (my $rName = shift @array1) { 
    my $bName = shift @array1 ; 
    ## Do something now with the value 
}
##And now, I want that I can use @array1 again with the original elements residing

如何实现?

最佳答案

在Perl 5.36你将能够做到这一点:

for my ($rName, $bName) (@array1) { ... }

https://stackoverflow.com/questions/71321797/

相关文章:

python - 两个日期时间之间的 15 分钟间隔数

python - 极地 : switching between dtypes within a Da

r - 与另一列中的变量相比,如何找到 R 列中两两变量之间的共同变量数?

c++ - 键入 “$” 命令不会跳转到行尾 [光标设置为 “|”(条形/管道)而不是 block

python - 如何在不完全用 Python 重写的情况下在函数内部添加、删除和编辑某些行?

swift - 如何快速制作圆形或填充和圆形进度 View (使用 CAShapeLayers)

r - 根据 R 中的出生年份对人员进行分组

linux - 使用打印命令选择子域

python - 理解 python 的 len() 时间复杂度

python - 我们如何提取数据框中具有顺序值的行?