qi has asked for the wisdom of the Perl Monks concerning the following question:

I want to generate a chart using Chart::Graph::Gnuplot from a list of data files. This works:
gnuplot({"title" => "foo"}, [{"type" => "file"}, "cdb.7600.log"], [{"type" => "file"}, "cdb.8299.log"]);
ie. I get a chart with two data sets on it. However, I want to pass the list of filenames on the command line. Here's the manpage:
use Chart::Graph qw(gnuplot); gnuplot(\%global_options, @data_sets); gnuplot(\%global_options, [\%data_set_options, \@matrix], [\%data_set_options, \@x_column, \@y_column] +, [\%data_set_options, < filename >], ... );
So, it looks to me like I can pass a reference to an array of data sets, where a data set is a hash, filename pair.. Here's my attempt:
while($logfile = shift) { push @data_sets, ({"type" => "file"}, $logfile); } gnuplot({"title" => "foo"}, \@data_sets);
But, and here's the rub, the chart I get only ever has the first data set on it. Am I doing something stupid? (I hope so).

Any help would be appreciated, thanks.

Replies are listed 'Best First'.
Re: Stumped by Chart::Graph::Gnuplot parameters
by Masem (Monsignor) on Mar 05, 2001 at 19:07 UTC
    You're passing a reference to the data_sets array when the POD is saying that it needs an array. Try calling it with only "@data_sets" as opposed to "\@data_sets".
      To be clear, the final solution is:
      while($logfile = shift) { push @data_sets, [{"type" => "file"}, $logfile]; } gnuplot({"title" => "foo"}, @data_sets);

        the final solution is

        Heh!

        gnuplot( {title=>"foo"}, map {[{type=>"file"},$_]} @ARGV );
                - tye (but my friends call me "Tye")
      Hmph, I remember trying that and it didn't work "Data set must be an array...", but, if I replace the round brackets with square brackets on the push line, it works!

      To be honest, I'm sure that's what I tried originally... well, it always ends up in tears when I randomly insert \s and [s until something works.

      Thanks a lot.