我能在Perl中做类似以下的操作吗?
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 实现这个,但出于好奇,其他编程语言是否有类似的简洁语法呢?