Passing an array of arrays to an external function

J

joakim.grahl

I need to pass a list of arrays to a function gnuplot() in the CPAN
module Chart-Graph-3.2, like in the example at the bottom (from
http://search.cpan.org/~caidaperl/Chart-Graph-3.2/Graph/Gnuplot.pm).

Say I wish to plot the following functions (as in the example):
@plots = ($data, $fnc1, $fnc2);

Then I can't do:
gnuplot(\%options, @plots);

which drives me crazy :)
How can I pass the array of arrays, @plots, to gnuplot(), without
explicitly saying $plots[0], $plots[2], ... etc
- I've also tried doing stuff like this:
gnuplot(\%options, join(", ", @plots);

Any help greatly appreciated!

- Joakim



SNIP:

my %options = (
'title' => 'plot functions example',
'output file' => 'gnuplot5.png',
);

my $data = [{ 'title' => 'data 1',
'style' => 'lines',
'type' => 'matrix',
},
[
[0,10],
[3,30],
[6,0],
[9,-10],
[12,-0],
]
];

my $fnc1 = [{ 'title' => 'function 1',
'style' => 'lines',
'type' => 'function',
},
'10*sin(x)+2*cos(1.1 * x)+.5*tan(x)'
];

my $fnc2 = [{ 'title' => 'function 2',
'style' => 'lines',
'type' => 'function',
},
'20*sin(sqrt(2**x))/sqrt(2**x)'
];

gnuplot(\%options, $data, $fnc1, $fnc2);

/SNIP
 
J

joakim.grahl

Figured it out :)
When push-ing to @plots, the first entry was always NULL, and this
crashed Gnuplot...
Fixing this, and the generic call, gnuplot(\%options, @plots), worked
fine every time :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top