1

この例を考えてみましょう:

#!/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 の実装を理解できません。

4

1 に答える 1