为什么在没有块的情况下调用 eval 会终止这个 Perl 程序?
Why does calling eval without a block terminate this Perl program?
以下程序在第二次调用 eval 时停止。这是预期的吗?我阅读了 perldoc -f eval 并惊讶地发现 print "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";
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
被调用,然后字符串 it returns 被求值。
… 除了它不是 return 字符串。它使程序死掉,所以 eval
永远不会被调用。
以下程序在第二次调用 eval 时停止。这是预期的吗?我阅读了 perldoc -f eval 并惊讶地发现 print "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";
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
被调用,然后字符串 it returns 被求值。
… 除了它不是 return 字符串。它使程序死掉,所以 eval
永远不会被调用。