Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hello fellow Monks!
I have made this script for creating histogram plots:
sub save_chart { my $chart = shift or die "Need a chart!"; my $name = shift or die "Need a name!"; local(*OUT); my $ext = 'png'; open(OUT, ">$name.$ext") or die "Cannot open $name.$ext for write: $!"; binmode OUT; print OUT $chart->gd->$ext(); close OUT; } use GD::Graph::bars; use GD::Graph::hbars; use GD::Graph::colour; my @data = ( ["name1", "name2", "name3","name4"], [23, 26, 53, 27], [77, 74, 47, 73] ); my @names = qw/sample15 sample15-h/; my $font_dir = '/usr/share/fonts/truetype'; my $font_file = "$font_dir/freefont/FreeSans.ttf"; for my $my_graph (GD::Graph::bars->new, GD::Graph::hbars->new(700,500) +) { my $name = shift @names; print STDERR "Creating image\n"; $my_graph->set( bgclr => 'white', box_axis => 0, y_max_value => 100, dclrs => ['#ff782a', '#6daa3a'], title => 'MY_TITLE', bar_width => 10, bar_spacing => 4, y_tick_number => 2, cumulate => 2, borderclrs => $my_graph->{dclrs}, bar_spacing => 4, transparent => 0, x_label_position => 0.5, tick_length => -4, axis_space => 6, x_ticks => 0, bar_spacing => 1, bargroup_spacing => 20, fgclr => '#bbbbbb', axislabelclr => '#333333', labelclr => '#333333', textclr => '#333333', legendclr => '#333333', legend_placement => 'DC', legend_marker_width => 12, legend_marker_height => 12, legend_spacing => 6, long_ticks => 0, borderclrs => [undef] ); $my_graph->set_title_font($font_file, 16); $my_graph->set_x_label_font($font_file, 16); $my_graph->set_y_label_font($font_file, 16); $my_graph->set_x_axis_font($font_file, 11); $my_graph->set_y_axis_font($font_file, 11); $my_graph->set_legend_font($font_file, 11); $my_graph->set_legend(qw(%leg1 %leg2)); $my_graph->plot(\@data); save_chart($my_graph, $name); }

Can you please tell me how I can pass the arrays in @data instead of hard-coding them inside the script? Because I want to make the script "universal"... I mean, if I have 3 arrays, namely @array_names, @array_numbers1 and @array_numbers2, how do I pass their values into the array @data?
Thank you!

In reply to How to pass arrays into this program? by Anonymous Monk

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (11)
    As of 2014-04-17 08:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (441 votes), past polls