我有一个数组,比如 @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/