如何在Perl中使用变量断言?

Ale*_*lex 7 python debugging perl assertions

如何在Perl中检查变量是否具有特定值?是否有命令停止脚本的执行以查找其中的一些变量?

我想知道我是否可以使用Pythonic插入实践:

    assert 0, (foo, bar)
Run Code Online (Sandbox Code Playgroud)

以无debuger的方式调试脚本?

Tel*_*hus 12

快速CPAN搜索建议Carp :: Assert.

  • +1输入比我更快的字符。我将编辑该URL以使其与版本无关。 (2认同)
  • @SinanÜnürWow,实际上是“一秒钟”!还没看过:) (2认同)

Sin*_*nür 8

请参阅Carp :: Assert:

use Carp::Assert;

$next_sunrise_time = sunrise();

# Assert that the sun must rise in the next 24 hours.
assert(($next_sunrise_time - time) < 24*60*60) if DEBUG;

# Assert that your customer's primary credit card is active
affirm {
    my @cards = @{$customer->credit_cards};
    $cards[0]->is_active;
};
Run Code Online (Sandbox Code Playgroud)


nik*_*nik 3

PerlMonks有一个脚本引入了快速断言方法。

速度很重要,因为 Perl 是解释性的,任何内联检查都会影响性能(例如,与简单的 C 宏不同)


我不确定这些东西是否可以直接使用。


好的!这就是我正在寻找的 - PDF 警告:Test-Tutorial.pdfTest::Harness用于编写 Perl 模块测试。