Hello Monks!!! Good Day...

I am trying a simple graph/chart plot but I have a string which contains data that can be split with "/\s+/" however, the data with which I want to plot the graph lies in column 3 and column 4.

I tried to load the contents of $tb2 into an array @plot_data and loop through the array but I do not get what I expect. Could you please correct me from what I have done. I know its fairly simple but my bad

#!/usr/bin/env perl -l use strict; use warnings; use GD::Graph::bars; #in my code, the value of $tb2 below is returned by another function, +below is for simplicity, but this is how my string looks like. my $tb2="Date Start Time End Time Egress Sent 08-15-2013 00:22:22 00:22:29 16.53 3.85 08-15-2013 01:22:22 01:22:28 17.05 3.6 08-15-2013 02:22:23 02:22:28 16.79 3.61 08-15-2013 03:22:24 03:23:27 103.89 37.29 08-15-2013 04:22:24 04:22:26 2.1 0.18 08-15-2013 11:22:25 11:25:11 73.72 60.98 08-15-2013 12:22:25 12:27:55 146.65 133.68" ####What I tried: my @plot_data=(split '/\s+/',$tb2); for (@plot_data){ print $plot_data[1]; my @graph = ( ["$plot_data[1]"], ["$plot_data[4]"], ["$plot_data[5]"], ); } ####What I am trying to do: # my @graph = ( # [#all columns in "Egress" from $tb2, seperated by comma], # [#all columns in "Sent" from $tb2, seperated by comma], # ); for my $my_graph (GD::Graph::bars->new) { print STDERR "Processing Graph\n"; $my_graph->set( x_label => 'Timestamp', y_label => 'Data Conveyed/Sent', title => 'Conveyed Vs. Sent', long_ticks => 1, y_max_value => 200, y_tick_number => 8, y_label_skip => 2, bar_spacing => 3, shadow_depth => 4, accent_treshold => 200, transparent => 0, ); print @graph; open(IMG, '>file.gif') or die $!; binmode IMG; $my_graph->set_legend('Conveyed', 'Sent'); my $gd = $my_graph->plot(\@graph); #save_chart($my_graph, "Graph"); print IMG $gd->gif; close IMG; }

In reply to Loading specific columns into arrays by sidsinha

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.