OUTER: {
for (;;) {
defined( my $_ = <$fh> ) or last OUTER;
if (/alpha/) {
f();
last;
} else {
g();
}
}
while (<$fh>) {
g();
}
}
Update: The remainder of this post is wrong.
You can get rid of the duplicate g() by making the loops bottom tested.
OUTER: {
defined( my $_ = <$fh> ) or last OUTER;
for (;;) {
if (/alpha/) {
f();
last;
}
defined( $_ = <$fh> ) or last OUTER;
}
for (;;) {
g();
defined( $_ = <$fh> ) or last OUTER;
}
}
You can squish it down a bit:
LOOP: {
defined( my $_ = <$fh> ) or last;
if (/alpha/) {
f();
redo;
}
for (;;) {
g();
defined( $_ = <$fh> ) or last;
}
}
Look at that, g() is not even duplicated anymore!!
|