Posso fare qualcosa come il seguente in Perl?Posso tirare l'elemento successivo all'interno di un ciclo Foreach 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;
}
}
Aggiornamento: Ho bisogno di questo in Perl, ma per curiosità: Do altre lingue hanno una sintassi pulito per questo?
Bello. Nel mio caso, distruggere l'originale non è nemmeno un problema, quindi posso fare a meno della copia. – Thilo