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.
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.