我可以在Perl中做如下的事情嗎?我可以從Perl foreach循環中獲取下一個元素嗎?
foreach (@tokens) {
if (/foo/){
# simple case, I can act on the current token alone
# do something
next;
}
if (/bar/) {
# now I need the next token, too
# I want to read/consume it, advancing the iterator, so that
# the next loop iteration will not also see it
my $nextToken = .....
# do something
next;
}
}
更新:我需要這在Perl,但爲了好奇:難道其他語言有一個整潔的語法?
不錯。就我而言,銷燬原件甚至不是問題,所以我可以在沒有副本的情況下完成。 – Thilo 2010-06-05 14:29:45