Well, now we have a few things to work on... (since you asked for general pointers as well as the help on the main problem, I'll go on at length).

First, there has to be a better way to do this:

@dates = `mysqlshow --password=\'xxxxxxx\' pzbg001`; shift @dates; shift @dates; shift @dates; shift @dates; pop @dates; foreach $date(@dates){ chomp $date; $date =~ s/ //g; $date =~ s/\|//g; $date =~ s/\-//g; $date =~ s/Tables//g; $date =~ s/\+//g; ...
I'd prefer a query that asks for names of tables (I don't know mysql so much, but in oracle, I'd do "select table_name from user_tables" -- 'user_tables' is an oracle-internal table, the same on every server, that lists information on all the user tables in the current user account). If you really want to do this via a back-tick command, and your table names are always numeric dates with underscores, try:
@dates = map { /^\|\s+([\d_]+)\s+\|$/ } `mysqlshow --...`
(For that matter, I'd use "@tables" as the array name there.)

Next, building the query is simpler than you seem to think:

$query = "select $result from $date where inintf=$inint";
Now, I was about to say you have the "sth->finish" call inside the while loop instead of outside (where it belongs), but then I realized that your indentation is still out of whack, making it harder to understand the code.

Another thing that's a little misleading here is that you are, in effect, running the same query on several tables, and each time you run it, you get exactly one scalar value, but you use a "while" loop with a nested "foreach" loop to retrieve that single value.

And finally, getting to the real problem, you are probably doing the wrong thing with @data = [\@dates, \@rage] -- the plot function probably wants an array of data points to graph, where each point is an array having one X coord.value and one Y coord.value (but I don't know GD at all -- you should check the docs on that). Anyway, if my guess is right, you should try it like this (this is the whole thing of doing the queries and assembling the array for plotting):

# get the list of tables (table names are \d+_\d+_\d+): my @dates = map { /^\|\s+([\d_]+)\s+\|$/ } `mysqlshow --...` # query each table for sum of traffic, # push table_name (i.e. date) and traffic sum onto @data: my @data = (); for my $date ( @dates ) { my $query = "select $result from $date where inintf=$inint"; my $sth = $dbh->prepare($query); if (!$sth) { die "Illegal query: $query" }; $sth->execute; my $octets = ($sth->fetchrow_array)[0]; # don't chomp it! $sth->finish; push @data, [ $date, $octets/(1024*1024) ]; } # do all that other GD stuff... then: my $myimage = $mygraph->plot(\@data) or die $mygraph->error; # and on to the web page...
update: added some commentary to the code; also added some more "my" scopers.

In reply to Re: Re: Re: GD::Graph::lines problem! by graff
in thread GD::Graph::lines problem! by Baiul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.