1
考慮這個例子:perl gnuplot是可以傳遞數組作爲數組?
#!/usr/bin/perl -w
use strict;
use Chart::Gnuplot;
# Initiate the chart object
my $chart = Chart::Gnuplot->new(
output => "plotStyle_1.png",
);
# A line
my $lines = Chart::Gnuplot::DataSet->new(
func => "cos(x)",
style => "lines",
title => "Plot a line",
);
# Points
my $points = Chart::Gnuplot::DataSet->new(
func => "sin(x)",
style => "points",
title => "Plot points",
);
# Points on a line
my $linespoints = Chart::Gnuplot::DataSet->new(
func => "-atan(x)",
style => "linespoints",
title => "Plot points on a line",
);
# Plot the graph
$chart->plot2d($lines, $points, $linespoints);
我想是在plot2d 3個對象(在代碼最後一行)推到一個數組並調用它是這樣的:
$chart->plot2d(@array);
這是實施plot2d
sub plot2d
{
my ($self, @dataSet) = @_;
&_setChart($self, \@dataSet);
my $plotString = join(', ', map {$_->_thaw($self)} @dataSet);
open(GPH, ">>$self->{_script}") || confess("Can't write $self->{_script}");
print GPH "\nplot $plotString\n";
close(GPH);
# Generate image file
&execute($self);
return($self);
}
* 是否可以使用數組作爲參數調用它? * 請注意,即時消息不是專家在perl我無法理解plot2d的執行情況