当我运行这个时:
use feature ':5.10';
$x=1;
given ($x) {
when(1) {
say '1';
$x = 2;
continue;
}
when (2) {
say '2';
}
}
这应该同时打印 1 和 2,但它只打印 1。我是不是遗漏了什么?
编辑:
我添加了 $x = 2 但它仍然只打印“1”
最佳答案
参见 perlsyn手册页:
given(EXPR) will assign the value of EXPR to $_ within the lexical scope of the block
此代码输出 1 和 2:
use feature ':5.10';
$x=1;
given ($x) {
when(1) {
say '1';
$_ = 2;
continue;
}
when (2) {
say '2';
}
}
关于perl - 为什么我的 continue 在 Perl 5.10 中不执行下一个 when block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2539570/