Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PERL RRDTTOL:带条件图例的图形子例程_Perl_Rrdtool - Fatal编程技术网

PERL RRDTTOL:带条件图例的图形子例程

PERL RRDTTOL:带条件图例的图形子例程,perl,rrdtool,Perl,Rrdtool,我做不到的蠢事 在Perl中,使用RRDTool(rrds模块),我创建了一个公共子例程来创建不同时间段(1天,1周,…)的图形。 我想使用一些子参数来显示可选的图例 使用以下代码,这不会生成任何图形 #!/usr/bin/perl use strict; use OWNet; use RRDs; use warnings; use diagnostics; my $rrd = '/var/rrd/electricite.rrd'; my $img = '/mnt/ds211/web/';

我做不到的蠢事

在Perl中,使用RRDTool(rrds模块),我创建了一个公共子例程来创建不同时间段(1天,1周,…)的图形。 我想使用一些子参数来显示可选的图例

使用以下代码,这不会生成任何图形

#!/usr/bin/perl
use strict;
use OWNet;
use RRDs;
use warnings;
use diagnostics;

my $rrd = '/var/rrd/electricite.rrd';
my $img = '/mnt/ds211/web/';

&CreateGraph("conso","Consommation electrique 1 heure","1h",1);

sub CreateGraph
# inputs:   $_[0]: sensor_rrd_name
#       $_[1]: chart title
#       $_[2]: interval period (1h,24h,7d,1m,1y,10y)
#       $_[3]: Puissance instantanee (1/0)
{
    my $temp_graph;
    $temp_graph ="\"$img$_[0]-$_[2].png\",";
    $temp_graph .="\"--start=end-$_[2]\",";
    $temp_graph .="\"--end=now\",";
    $temp_graph .="\"--width=600\",";
    $temp_graph .="\"--height=200\",";
    $temp_graph .="\"--slope-mode\",";
    $temp_graph .="\"--title=$_[1]\",";
    $temp_graph .="\"--vertical-label=Watt\",";
    $temp_graph .="\"--lower-limit=0\",";
    $temp_graph .="\"--alt-autoscale-max\",";
    $temp_graph .="\"DEF:energy=$rrd:$_[0]:AVERAGE\",";
    $temp_graph .="\"CDEF:Watt=energy,3600,*\",";
    $temp_graph .="\"LINE2:Watt#0000FF:\",";
    $temp_graph .="\"AREA:Watt#00FF00:\",";
    $temp_graph .="\"VDEF:WattHour=energy,TOTAL\",";

    if ($_[3]==1)
    {
        $temp_graph .="\"GPRINT:Watt:LAST:  Puissance instantanee\\: %6.2lf%sW\",";
    }

    $temp_graph .="\"GPRINT:WattHour:   Consommation totale\\: %6.2lf%sWh\\n\",";
    $temp_graph .="\"GPRINT:Watt:MIN:  Puissance min\\: %6.2lf%sW\",";
    $temp_graph .="\"GPRINT:Watt:AVERAGE:  Puissance moyenne\\: %6.2lf%sW\",";
    $temp_graph .="\"GPRINT:Watt:MAX:  Puissance max\\: %6.2lf%sW\"";

    RRDs::graph ("$temp_graph");

    if ($ERROR = RRDs::error)
    {
        print "$0: failed to generate graph $_[0] data into rrd: $ERROR\n";
    }
}

谢谢你

我想猜测一下,标题中的空格字符正在偏离选项解析。在$temp_图形字符串的标题周围加上一些单引号怎么样

我希望这有帮助

my $temp_graph = qq{"$img$_[0]-$_[2].png",};
$temp_graph .= qq{"--start=end-$_[2]",};
$temp_graph .= qq{"--end=now",};
$temp_graph .= qq{"--width=600",};
$temp_graph .= qq{"--height=200",};
$temp_graph .= qq{"--slope-mode",};
$temp_graph .= qq{"--title='$_[1]'",};
$temp_graph .= qq{"--vertical-label=Watt",};
$temp_graph .= qq{"--lower-limit=0",};
$temp_graph .= qq{"--alt-autoscale-max",};
$temp_graph .= qq{"DEF:energy=$rrd:$_[0]:AVERAGE",};
$temp_graph .= qq{"CDEF:Watt=energy,3600,*",};
$temp_graph .= qq{"LINE2:Watt#0000FF:",};
$temp_graph .= qq{"AREA:Watt#00FF00:",};
$temp_graph .= qq{"VDEF:WattHour=energy,TOTAL",};

if ($_[3]==1)
{
    $temp_graph .= qq{"GPRINT:Watt:LAST:  Puissance instantanee\\: %6.2lf%sW",};
}   

$temp_graph .= qq{"GPRINT:WattHour:   Consommation totale\\: %6.2lf%sWh\\n",};
$temp_graph .= qq{"GPRINT:Watt:MIN:  Puissance min\\: %6.2lf%sW",};
$temp_graph .= qq{"GPRINT:Watt:AVERAGE:  Puissance moyenne\\: %6.2lf%sW",};
$temp_graph .= qq{"GPRINT:Watt:MAX:  Puissance max\\: %6.2lf%sW"};

print join qq{",\n"}, split /","/, $temp_graph;
print "\n";

问题是您正在向rrdtool传递一个字符串,而不是带有参数的数组

而不是

RRDs::graph ("\"graph.gif\",\"DEF:...\" ...");
你应该打电话来

RRDs::graph ("graph.gif","DEF:...","...");`
如果你想事先准备好你的论点,那么你可以使用

my @args = ("graph.gif","DEF:...","...")
RRDs::graph(@args);

希望这能有所帮助。

但。。为了避免所有转义的双引号,您可以使用qq指定另一个字符作为插入引号-例如qq!“$img$\[0]-$\[2].png”!
my $temp_graph = qq{"$img$_[0]-$_[2].png",};
$temp_graph .= qq{"--start=end-$_[2]",};
$temp_graph .= qq{"--end=now",};
$temp_graph .= qq{"--width=600",};
$temp_graph .= qq{"--height=200",};
$temp_graph .= qq{"--slope-mode",};
$temp_graph .= qq{"--title='$_[1]'",};
$temp_graph .= qq{"--vertical-label=Watt",};
$temp_graph .= qq{"--lower-limit=0",};
$temp_graph .= qq{"--alt-autoscale-max",};
$temp_graph .= qq{"DEF:energy=$rrd:$_[0]:AVERAGE",};
$temp_graph .= qq{"CDEF:Watt=energy,3600,*",};
$temp_graph .= qq{"LINE2:Watt#0000FF:",};
$temp_graph .= qq{"AREA:Watt#00FF00:",};
$temp_graph .= qq{"VDEF:WattHour=energy,TOTAL",};

if ($_[3]==1)
{
    $temp_graph .= qq{"GPRINT:Watt:LAST:  Puissance instantanee\\: %6.2lf%sW",};
}   

$temp_graph .= qq{"GPRINT:WattHour:   Consommation totale\\: %6.2lf%sWh\\n",};
$temp_graph .= qq{"GPRINT:Watt:MIN:  Puissance min\\: %6.2lf%sW",};
$temp_graph .= qq{"GPRINT:Watt:AVERAGE:  Puissance moyenne\\: %6.2lf%sW",};
$temp_graph .= qq{"GPRINT:Watt:MAX:  Puissance max\\: %6.2lf%sW"};

print join qq{",\n"}, split /","/, $temp_graph;
print "\n";