以下程序在第二次调用eval时停止。这是预期的吗?我读了perldoc -f eval,并且对于没有显示打印“2:...”的输出感到惊讶。
eval {die("The curly braces seem to rescue me! Life moves on")};
print "1: $@\n";
eval die("Program actually terminates here! Subsequent prints are not shown");
print "2: $@\n";
答案 0 :(得分:5)
perldoc -f eval
eval EXPR eval BLOCK eval In the first form, often referred to as a "string eval", the return value of EXPR is parsed and executed as if it were a little Perl program.
...所以调用die
然后评估它返回的字符串。
...除了它不返回字符串。它使程序死亡,因此永远不会调用eval
。