我正在尝试实现用perl编写的slapd_
munin插件,我几乎无能为力。 The full plugin is available here。我得到的错误就是这个:
Use of uninitialized value in concatenation (.) or string at
/etc/munin/plugins/slapd_localhost line 232, <DATA> line 275.
第232行就是这个:
my $searchdn = $ops{$action}->{'search'} . "," . $basedn;
我尝试通过输出所有变量/对象进行调试,如下所示:
use Data::Dumper; # top of script
# [...]
print Dumper(%ops);
print "action = [$action]\n";
print "basedn = [$basedn]\n\n";
my $searchdn = $ops{$action}->{'search'} . "," . $basedn;
当我再次运行时,这是我获得的:
[...] # 15 other variables belonging to $ops
$VAR16 = {
'info' => 'The graph shows the number of Waiters',
'search' => 'cn=Waiters',
'desc' => 'The current number of Waiters',
'filter' => '(|(cn=Write)(cn=Read))',
'title' => 'Number of Waiters',
'label2' => {
'read' => 'Read',
'write' => 'Write'
},
'vlabel' => 'Waiters'
};
action = [localhost]
action = [cn=Monitor]
Use of uninitialized value in concatenation (.) or string at /etc/munin/plugins/slapd_localhost line 237, <DATA> line 275.
由于似乎设置了所有变量,我真的不明白我得到的错误信息
问:有人可以就如何调试此脚本提供建议吗?
答案 0 :(得分:3)
您应该将引用转储到%ops
,如
print Dumper \%ops;
这将使调试输出更清晰。为了说明,请考虑
的输出#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my %h = (foo => { bar => 1 }, baz => { quux => 3 });
print "No reference:\n",
Dumper(%h),
"\n",
"Reference:\n",
Dumper(\%h);
请注意在后半段你如何更清楚地看到结构:
No reference: $VAR1 = 'baz'; $VAR2 = { 'quux' => 3 }; $VAR3 = 'foo'; $VAR4 = { 'bar' => 1 }; Reference: $VAR1 = { 'baz' => { 'quux' => 3 }, 'foo' => { 'bar' => 1 } };
你削减了输出的关键位。 $VAR15
的价值是多少?是"localhost"
还是其他什么?
当您打印$searchdn
时,它的价值是什么?