-6ren">
gpt4 book ai didi

perl - 返回字符串的子例程发出有关 "Useless use of a constant in void context"的警告

转载 作者:行者123 更新时间:2023-12-03 01:59:38 25 4
gpt4 key购买 nike

我在模块中有一个简单的函数blurb,它返回一些文本

package Il::NetApp::Dox::FlashCache;

use strict;
use warnings;
no if $] >= 5.018, warnings => "experimental::smartmatch";

use Carp;
use Carp::Heavy;
use Data::Dumper;

use FindBin qw($Bin);
use Il::SysMon::Tools 3.2.1 qw( :debug :special_chars :text_format :help_snippets);
use Il::NetApp::Tools qw( :help_snippets );

# ===========================================================================
# = Texte - ab hier wird übersetzt =
# ===========================================================================

# ===========================================================================
# Markdown Syntax in blurb, extra und examples=>txt!
#
# Verwendbare Variablen in den Texten:
#
# $VERBOSE_HINT = Hinweis -v einzusetzen
#
# ===========================================================================

sub blurb {
q{Checks several metrics of NetApps FlashCache (PAM II).}; # Line 27
}

sub extra {
<<END_EXTRA,
This plugin checks various performance counters of the NetApp-system.

A list of supported counters is printed via the `--counter` switch.

$HELP_DISCOVER_COUNTERS
END_EXTRA
}

#
# Examples: Hier ist jeweils nur txt => zu übersetzen
#

sub simple_examples {
my $examples =
[
{
cmd => q{--explore=counters},
txt => q{List all available and supported counters on the target system.}
},
{
cmd => q{-z hit_percent -w 0 -c 0},
txt => q{Monitor the hitrate for trendanalyses but do not alarm.}
},
]
; # Ende von my $examples =
return $examples;
}

# sub advanced_examples {
# my $examples =
# [
# {
# cmd => q{},
# txt => q{}
# },
# ]
# ; # Ende von my $examples =
# return $examples;
# }


# ===========================================================================
# = ENDE der Texte - ab hier ist nichts mehr zu übersetzen =
# ===========================================================================

1; # return true

在一台服务器上,我们偶尔会收到警告:

Useless use of a constant ("Checks several metrics of "...) in void context at .../lib/Il/NetApp/Dox/FlashCache.pm line 27.

如果 Perl 子例程是表达式,则返回最后执行的语句的值,并且此技术以前曾有效过。我无法使用 Perl v5.10.1 或 v5.18.2 重现该问题。

出现这些警告的网站正在运行 Perl v5.16.3

# perl --version

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 33 registered patches, see perl -V for more detail)

这可能是特定 Perl 版本中的错误吗?

最佳答案

空上下文是没有任何东西可以消耗返回内容的上下文。

当使用空原型(prototype)定义子时会出现警告:

use warnings;
sub blurb () { q(some string) }
blurb();

您能显示 NetApp/Dox/FlashCache.pm 第 27 行吗?

关于perl - 返回字符串的子例程发出有关 "Useless use of a constant in void context"的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50907938/

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