Passing an array of arrays to an external function

Discussion in 'Perl Misc' started by joakim.grahl@gmail.com, Feb 21, 2007.

  1. Guest

    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
     
    , Feb 21, 2007
    #1
    1. Advertising

  2. Guest

    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 :)
     
    , Feb 21, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Rossney
    Replies:
    0
    Views:
    2,118
    Robert Rossney
    Sep 1, 2003
  2. Philipp
    Replies:
    21
    Views:
    1,185
    Philipp
    Jan 20, 2009
  3. Cec Tre
    Replies:
    3
    Views:
    214
    Robert Klemme
    Mar 19, 2010
  4. Allen Walker

    Merging two arrays -> array of arrays

    Allen Walker, May 21, 2010, in forum: Ruby
    Replies:
    6
    Views:
    180
    Jesús Gabriel y Galán
    May 21, 2010
  5. Hal Vaughan

    Arrays Of Arrays: Is it an Array or Scalar?

    Hal Vaughan, Feb 5, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    166
    Tore Aursand
    Feb 6, 2004
Loading...

Share This Page