This one just came up: How do I break out of an if
statement? I have a long if statement, but there is one situation where I can break out of it early on.
In
Another alternative is to use an anonymous subroutine.
Note: I don't recommend this method because of the added scoping complexity (see note below); it is just for completeness of possible answers.
if( $true_condition ){
(sub{
return if $true_condition;
...
})->();
}
Note: any variables declared w/in the routine must use our
instead of my
if you wish to use them in the rest of the code.