如果没有匹配的案例 block ,有什么方法可以运行代码块?例如:
switch($a) {
case // {}
case // {}
...
# DO SOMETHING IF NONE OF THE ABOVE CASES WERE MATCHED
}
else
不是我要找的,因为它仅适用于最后一个案例 block 。
最佳答案
Perl 5.10 中总会有切换,当然,如果你正在运行它。
use feature qw(switch);
given($a){
when(1) { print 'Number one'; }
when(2) { print 'Number two'; }
default { print 'Everything else' }
}
关于Perl 切换语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4919245/