The Fatal module was added to the Perl core in version 5.05 (1998). The Fatal module has some significant shortcomings and inconsistencies in its API which couldn't be fixed in a backwards compatible way (ie: fixing the API would break existing code which used Fatal).
The newer autodie module was written to provide a more consistent API and to allow the effect of the pragma to be lexically scoped rather than global (which can have unexpected side effects).
If you have a choice, you should definitely prefer autodie. It will be included as a core module in the upcoming 5.12 release of Perl.
The autodie module requires Perl 5.8. About the only reason you'd use Fatal is if you were stuck with a really old version of Perl (eg: 5.6), but 5.8 has been out since 2002 so hopefully that won't be the case for you.
Fatal has been obsoleted by the new autodie pragma. Please use autodie in preference to Fatal. autodie supports lexical scoping, throws real exception objects, and provides much nicer error messages.
Another reason to use autodie instead of Fatal is to avoid this bug (from the BUGS section of the Fatal docs):
Fatal clobbers the context in which a
function is called and always makes it
a scalar context, except when the
:void tag is used. This problem does
not exist in autodie.
发布评论
评论(3)
Fatal 模块在 5.05 (1998) 版本中被添加到 Perl 核心中。 Fatal 模块在其 API 中存在一些重大缺陷和不一致,无法以向后兼容的方式修复(即:修复 API 会破坏使用 Fatal 的现有代码)。
编写较新的 autodie 模块是为了提供更一致的 API,并允许 pragma 的效果在词法范围内而不是全局(这可能会产生意想不到的副作用)。
如果有选择的话,你肯定会更喜欢autodie。它将作为核心模块包含在即将发布的 Perl 5.12 版本中。
autodie 模块需要 Perl 5.8。您使用 Fatal 的唯一原因是如果您一直使用 Perl 的旧版本(例如:5.6),但 5.8 自 2002 年以来就已发布,所以希望您不会遇到这种情况。
The Fatal module was added to the Perl core in version 5.05 (1998). The Fatal module has some significant shortcomings and inconsistencies in its API which couldn't be fixed in a backwards compatible way (ie: fixing the API would break existing code which used Fatal).
The newer autodie module was written to provide a more consistent API and to allow the effect of the pragma to be lexically scoped rather than global (which can have unexpected side effects).
If you have a choice, you should definitely prefer autodie. It will be included as a core module in the upcoming 5.12 release of Perl.
The autodie module requires Perl 5.8. About the only reason you'd use Fatal is if you were stuck with a really old version of Perl (eg: 5.6), but 5.8 has been out since 2002 so hopefully that won't be the case for you.
引用 Fatal 文档
To quote the Fatal documentation
使用 autodie 而不是 Fatal 是为了避免这个 bug(来自 致命 文档):
Another reason to use autodie instead of Fatal is to avoid this bug (from the BUGS section of the Fatal docs):