http://www.perlmonks.org?node_id=220757

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

I would like to read data into an array from a text file ( data.txt ). What does the @data actualy contain in the example below ( ref's to anonymous arrays ) ?

Once I read in the 3 lines, how do I push them onto @data correctly ?

data.txt contains 3 lines : "Jan","Feb","Mar","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec"
3,5,7,2,4,9,6,3,6,1
8,4,1,8,9,3,5,1,3,8

use GD::Graph::lines; use GD::Graph::Map; print STDERR "Processing sample 5-1\n"; open IN, "<data.txt"; @mydata = <IN>; close IN; # # I would like to read the 3 lines in the data.txt file into data arra +y below. # The same data would be in the text file as in the data array below. # @data = ( ["Jan","Feb","Mar","Apr","May","June","July","Aug","Sep", +"Oct","Nov","Dec"], [ (3,5,7,2,4,9,6,3,6,1) ], [ (3,5,7,6,4,9,6,3,9,1) ] ); $my_graph = new GD::Graph::lines(); $my_graph->set( x_label => 'Month', y_label => 'Measure of success', title => 'A Simple Line Graph', y_max_value => 10, y_min_value => 0, y_tick_number => 10, y_label_skip => 1, box_axis => 0, line_width => 5, ); open PNG, ">sample51.png"; binmode PNG; #only for Windows like platforms print PNG $my_graph->plot(\@data)->png; close PNG; $map = new GD::Graph::Map($my_graph, info => '%l'); open HTML, ">sample51.html"; print HTML "<HTML><BODY BGCOLOR=white>\n". ($map->imagemap("sample51.png", $ref)). "</BODY></HTML>"; close HTML; __END__
Thx
Ginder Singh.