Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute perl code within function call

Status
Not open for further replies.

joakimk

MIS
Joined
Feb 21, 2007
Messages
2
Location
NO
I need to pass a list of arrays to an external (?) function called gnuplot(), like in the example at the bottom (from
What if I have this:
@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

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);
 
What if I have this:
@plots = ($data, $fnc1, $fnc2);

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

sure you can, what's the problem you're having when doing that? @plots is an array of references.


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I figured it out :)
The problem was simply that push-ing to @plots left the first entry ($plots[0]) empty (NULL), which screwed up the call to Gnuplot.

Thanks anyway :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top