Perl Breaking out of an If statement

后端 未结 7 845
深忆病人
深忆病人 2021-02-05 03:50

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

7条回答
  •  一生所求
    2021-02-05 04:19

    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.

提交回复
热议问题