for ( @some_array ) {
if ( $_ eq 'foo' ) {
print "skipping foo\n";
next;
}
if ( $_ eq 'bar' ) {
handle_bar($_);
next;
}
handle_rest($_);
}
####
for ( @some_array ) { ... }
# to
my $index = -1;
while ( ++$index <= $#some_array ) { ... }
####
my $flag;
my $index = -1;
while ( ++$index <= $#some_array ) {
if ( $_ eq 'foo' ) {
$flag = 'foo';
print "skipping foo\n";
last;
}
if ( $_ eq 'bar' ) {
$flag = 'bar';
handle_bar($_);
last;
}
handle_rest($_);
}
if ( $flag eq 'foo' ) {
while ( ++$index <= $#some_array ) {
if ( $_ eq 'bar' ) {
handle_bar($_);
last;
}
handle_rest($_);
}
}
else {
while ( ++$index <= $#some_array ) {
if ( $_ eq 'foo' ) {
print "skipping foo\n";
last;
}
handle_rest($_);
}
}
while ( ++$index <= $#some_array ) {
handle_rest($_);
}