in reply to Graphing basics..

I assume from your example there are a known number of files (say 3), each with one line of comma-separated items (the same number in each).

Here is a simple way to get the given lines into @data (not tested). It's a lot like the one by Ovid but simpler because I don't have to sort file names.

use strict; sub split_file_line { my $file = shift; open(IN, "<".$file) || die "cannot open $file: $!"; my @items = split /,/,chomp($_ = <IN>); close IN; return \@items; } my @data = (); my @files = qw(header_data.dat); my $nfiles = 3; for (my $i = 1; $i <= $nfiles; $i++) { push @files,"daily_data${i}.dat"; } foreach my $file (@files) { push @data, split_file_line($file); }

Replies are listed 'Best First'.
Re: Re: Graphing basics..
by Anonymous Monk on Mar 01, 2003 at 20:10 UTC
    Guys thank you for the input. The references were confusing me at first once I understood what kind of data is required and how to push it onto @data it made alot more sense.

    use GD::Graph::lines; use GD::Graph::Map; use GD::Graph::Data; my ( @hyd,@aut,@fil,@cli,@mis,@days,@std,@files ); @data = (); @files = ( "work_days.dat","std.dat","hyd_daily.dat","aut_daily.dat"," +cli_daily.dat","mis_daily.dat"); sub split_file_line { my $file = shift; open IN, "<$file" || die "cannot open $file: $!"; my $temp = <IN>; my @items = ( split /,/,$temp ); close IN; return \@items; } foreach (@files) { push @data, split_file_line($_); } $my_graph = GD::Graph::lines->new(600,600); $my_graph->set( x_label => 'Working Days ', y_label => '% Percentage', title => 'Orders on Time ', y_max_value => 200, y_min_value => 0, y_tick_number => 20, y_label_skip => 1, box_axis => 0, line_width => 5 ); open PNG, ">p.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, ">p.html"; print HTML "<HTML><BODY BGCOLOR=white><CENTER>\n". ($map->imagemap("parker.png", $ref)). "</CENTER></BODY></HTML>"; close HTML; __END__