Sara said:
Can I exit a block early, as "last" operator does in a loop? Such as:
unless ($catsHaveWings)
{..do stuff
"escape" if $dogsHaveFins;
.. do more stuff
}
# I want "escape" to reenter HERE
You're already using one 'unless' block. Why not two?
unless ($catsHaveWings) {
# do stuff here
print "Doing stuff\n";
unless ($dogsHaveFins) {
print "Doing more stuff\n";
}
}
If you *really* need it, Perl does have goto, although I wouldn't use it to
jump more than a few lines if I used it at all. More explicitly: goto can
turn code into a mass of spaghetti and so should be used sparingly at most.
("You have entered a maze of twisty GOTOs, all alike...")
unless ($catsHaveWings) {
print "2 Doing stuff\n";
goto DOGS_HAVE_FINS if $dogsHaveFins;
#.. do more stuff
print "2 Doing more stuff\n";
}
DOGS_HAVE_FINS: