gpt4 book ai didi

perl - Perl 中的错误信息 "Use of uninitialized value in null operation"是什么意思?

转载 作者:行者123 更新时间:2023-12-01 03:58:56 28 4
gpt4 key购买 nike

Perl 中的错误消息“在空操作中使用未初始化的值”是什么意思?

我在谷歌上广泛搜索了这个,发现很多页面上人们讨论了这种形式的错误。然而,尽管我进行了搜索,但我一直无法理解这表示什么错误情况。请注意:我没有可以共享的源代码来演示此错误,因为它仅在“Test::More”下运行时出现在测试脚本中,并且涉及大量 XS 代码。我只是想了解一下此错误消息可能意味着什么。

最佳答案

查看 perldoc perldiag 对于“使用未初始化的值”。

  • Use of uninitialized value%s
    (W 未初始化) 使用未定义的值,就好像它已经定义一样。它被解释为 ""或 0,但也许这是一个错误。要抑制此警告,请为您的变量分配一个定义的值。

    为了帮助您找出未定义的内容,perl 会尝试告诉您 undefined variable (如果有)的名称。在某些情况下它不能这样做,因此它还会告诉您您在哪个操作中使用了未定义的值。但是请注意,perl 优化了您的程序,并且警告中显示的操作可能不一定按字面出现在您的程序中。例如, "that $foo"通常被优化为 "that "。 $foo ,并且警告将引用连接 (.) 运算符,即使没有 .在你的程序中。

  • 有趣的部分是弄清楚“in null 操作”的含义。它不是那么简单:
    my $x;
    $x;

    得到:
    Useless use of private variable in void context

    在这个阶段,我不确定;您可以通过显示触发消息的 Perl 脚本来提供帮助。

    在查看 Perl 源代码(我通常避免做的事情)之后,有许多测试包含诸如 ( t/lib/dbmt_common.pl ) 之类的注释:
    # Bug ID 20001013.009
    #
    # test that $hash{KEY} = undef doesn't produce the warning
    # Use of uninitialized value in null operation

    您还可以在 regen/opcodes 中找到对“空操作”的引用。 .空操作似乎是操作码 0。
    # Nothing.

    null null operation ck_null 0
    stub stub ck_null 0
    scalar scalar ck_fun s% S

    # Pushy stuff.

    pushmark pushmark ck_null s0

    如果您查看 opcode.h , 你可以找到:
    #ifndef DOINIT
    EXTCONST char* const PL_op_name[];
    #else
    EXTCONST char* const PL_op_name[] = {
    "null",
    "stub",
    "scalar",
    "pushmark",

    ...


    #ifndef DOINIT
    EXTCONST char* const PL_op_desc[];
    #else
    EXTCONST char* const PL_op_desc[] = {
    "null operation",
    "stub",
    "scalar",
    "pushmark",

    文件 cpan/Encode/lib/Encode/Encoding.pm包含评论(在某些 POD 中):
    =item -E<gt>renewed

    Predefined As:

    sub renewed { $_[0]->{renewed} || 0 }

    Tells whether the object is renewed (and how many times). Some
    modules emit C<Use of uninitialized value in null operation> warning
    unless the value is numeric so return 0 for false.

    我想你最好问 PerlMonks或者一些类似的地方,Perl 内部结构的大师们闲逛的地方。

    关于perl - Perl 中的错误信息 "Use of uninitialized value in null operation"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14889437/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com