in reply to Re^4: Keys and Values from Hash
in thread Keys and Values from Hash

My end goal is to create an HTML page, which will display a Column Chart

In that case, here's a long pass up the field for you ..

#!perl; use strict; use GD; use GD::Graph::bars; # test data my %spend = (); for ('A'..'Z'){ $spend{'Customer_'.$_} = { money9am => int rand(1000), money3pm => int rand(1000) }; }; # graph my $date = scalar localtime; my $graph = GD::Graph::bars->new(800,400); $graph->set( y_label => 'Spend', title => 'Customer spend for '.$date, bar_spacing => 5, cycle_clrs => 1, x_labels_vertical => 1, ) or die $graph->error; $graph->set_x_axis_font(gdMediumBoldFont); $graph->set_y_axis_font(gdMediumBoldFont); # table and graph data my @x=(); my @y=(); my $table = q!<table cellspacing="0" cellpadding="5" border="1">!; for my $cust (sort keys %spend){ my $spend = $spend{$cust}{'money9am'}+$spend{$cust}{'money3pm'}; push @x,$cust; push @y,$spend; $table .= qq!<tr><td>$cust</td><td align="right">$spend</td></tr>!; } $table .= q!</table>!; # plot my $gd = $graph->plot([\@x,\@y]) or die $graph->error; # save chart as gif (my $filename = $date) =~ s/ /_/g; $filename =~ s/://g; open IMG, '>',$filename.'.gif' or die $!; binmode IMG; print IMG $gd->gif; # create html open HTM, '>report.htm' or die $!; print HTM qq(<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http: +//www.w3.org/TR/html4/strict.dtd"> <head><title>Spend for $date</title></head> <body><h3>Spend for $date</h3> <p><img src="$filename.gif" alt="chart"></p> $table </body></html>);
For more graph options see GDGraph
poj