Hi monks,
I am trying to foreach through a data-file, retreive key values and form a graph with these values (one graph per line, each should turn out different). The problem is that when i print the graphs within the loop, the same single graph is being printed for each line and I think the program is only actually creating one graph each time it is ran, (not individual graphs). I tested the values in each array that are being passed to make the graph - and these are different for each line. I hope someone can help!
my @data = split /\n/, $data;
$data[2] =~ s/,/\t/g;
my @temps = $data[2];
my $temps = join ('', @temps);
@temps = split (/\s+/, $temps);
shift @temps;
foreach my $line (@file) {
@new = ();
push (@new, $+) while $line =~ m {
"([^\"\\]*(?:\\.[^\"\\]*)*)",?
| ([^,]+),?
|,
}gx;
push (@new, undef) if substr ($line, -1,1) eq ',';
join('', split(/(?=\w)/, @new));
shift @new;
# printing @temps and @new here prints different values for e
+ach line (of @new)
# prints same graph each time
my $plot = plot_graph (\@temps, \@new);
print qq(<img src=$plot>);
}
sub plot_graph {
my ($temps, $numbers) = @_;
my @graph_data = (\@$temps, \@$numbers);
my $graph = GD::Graph::lines ->new (600,600);
$graph->set(
x_label => 'Temperature degrees C',
y_label => 'Fluorescence Derivative',
x_max_value =>95,
y_max_value =>0.7,
x_label_position =>1/2,
x_tick_number =>20,
y_tick_number =>10
) or die $graph->error;
$graph->set (dclrs=> [qw(green red blue)]);
my $gb = $graph->plot(\@graph_data) or die $graph-
+>error;
open (IMG , ">temp/$$.png") or die $!;
binmode IMG;
print IMG $gb->png;
close IMG;
my $plot = "temp/$$.png";
return $plot;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.