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

my @y=(1..11); for ($ia=0;$ia<$text;$ia++) { @tempa=splice(@rfevma2437,0,11); $datasets[$ia]=Chart::Gnuplot::DataSet->new( xdata=>\@y, ydata=>\@tempa, style=>"lines", title => $sln[$ia], ); print "$datasets[$ia]\n"; push @temp1,$datasets[$ia]; } $rfevmchart->plot2d(@temp1);

Even though I am passing values to dataset objects of a GNUPlot through the for loop, I am able to plot only the last pushed value using plot2d. What can be the reason? Please do help. I am new to perl.

  • Comment on GnuPlot plot2d plots only last pushed value to the dataset object array.!!?
  • Download Code

Replies are listed 'Best First'.
Re: GnuPlot plot2d plots only last pushed value to the dataset object array.!!?
by hippo (Archbishop) on Jun 16, 2015 at 15:13 UTC

    Just a guess, but does it improve matters if you declare @tempa as my inside the loop? eg.

    my @tempa=splice(@rfevma2437,0,11);

    If @tempa is not local to the loop it doesn't go out of scope and so your references to it may be being overwritten each time through the loop.

    (Added note: Even if this doesn't fix the problem, it's still good practice to limit the scope of such variables. I'd also suggest calling it something slightly more meaningful like @yvals perhaps.)

      Thanks a Ton Man.. I wasted a whole day with this error. It worked. Thanks a lot. and sure, i will make sure i ll limit the scope of such variables.