如何在 Perl 中进行变量断言?
在 Perl 中如何检查变量是否具有特定值? 是否有命令可以停止脚本的执行以查找其某些变量?
我想知道我是否可以使用Pythonic的插入实践:
assert 0, (foo, bar)
以无调试器的方式调试脚本?
How can I check that a variable has a specific value in Perl? Is there a command to stop a script's execution to look up some of its variables?
I wonder if I can use the Pythonic practice of inserting:
assert 0, (foo, bar)
to debug scripts in a debuger-less way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您无法访问 Carp::Assert 所需的 Perl 5.9,则可以执行此操作。
You can do this if you do not have access to Perl 5.9 which is required for Carp::Assert.
我倾向于在代码中添加类似的内容,然后使用查找和替换来删除它们(在生产代码中)。
此外,“eval”可用于运行一段代码并捕获错误和可用于创建异常处理功能。 如果您断言某个值不为 0,也许您想抛出异常并以特殊方式处理该情况?
I tend to throw things like this in my code, and later use a find and replace to get rid of them (in production code).
Also, 'eval' can be used to run a section of code and capture errors and can be used to create exception handling functionality. If you are asserting that a value is not 0, perhaps you want to throw an exception and handle that case in a special way?
PerlMonks 中有一个脚本引入了快速断言方法。
速度很重要,因为 Perl 是解释性的,任何内联检查都会影响性能(例如,与简单的 C 宏不同)
我不确定这些东西是否可以直接使用。
好的! 这就是我正在寻找的 -- PDF 警告:Test-Tutorial.pdf< /a>.
Test::Harness
用于编写 Perl 模块测试。There is a script at PerlMonks that introduces a fast assert method.
Speed is important since Perl is interpreted and any inline checks will impact performance (unlike simple C macros for example)
I am not sure if these things are going to be directly usable.
Ok! This is what i was looking for -- PDF Warning: Test-Tutorial.pdf. The
Test::Harness
is used for writing Perl module tests.Smart::Comments 很好。
Smart::Comments are nice.
请参阅 Carp::Assert:
See Carp::Assert:
快速 CPAN 搜索建议 Carp::Assert。
A quick CPAN search suggests Carp::Assert.