I have an array of 100 floating point values. I rounded the values to the tenths place in order to create more matches on my histogram. I was wondering how to get these values in an array and put them into a histogram. I have previously checked other posts on PerlMonks, but I end up with errors in my code. I am relatively new to programming in general and I might lack certain programming etiquette or syntax.

use strict; use warnings; use Data::Dumper; use 5.010; use GD::Graph::histogram; use YAML; use CGI ':standard'; sub main { my $input = 'distance.txt'; unless(open(INPUT, $input)) { die "\nCannot open input\n"; } my @data; while(my $line = <INPUT>) { chomp $line; my @rounded = sprintf ("%.1f\n", $line); push @data, @rounded; my ( $filename, @data ) = @_; my $graph = new GD::Graph::histogram(400,600); $graph->set( y_label => 'Count', x_label => 'Distances', title => 'Histogram', x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 1, shadowclr => 'dred', transparent => 0, ) or warn $graph->error; my $image = $graph->plot(\@data) or die $graph->error; open( IMG, '>' . $filename ) or die $!; binmode IMG; print IMG $image->png; } } main();

These are the error messages I have been receiving.

Subroutine main::Dump redefined at /System/Library/Perl/5.18/CGI.pm li +ne 308. Use of uninitialized value $min in subtraction (-) at /Library/Perl/5. +18/GD/Graph/histogram.pm line 110, <INPUT> line 1. Use of uninitialized value $max in subtraction (-) at /Library/Perl/5. +18/GD/Graph/histogram.pm line 110, <INPUT> line 1. Use of uninitialized value $max in numeric le (<=) at /Library/Perl/5. +18/GD/Graph/histogram.pm line 118, <INPUT> line 1. Use of uninitialized value $upper in numeric le (<=) at /Library/Perl/ +5.18/GD/Graph/histogram.pm line 118, <INPUT> line 1. Use of uninitialized value $lower in addition (+) at /Library/Perl/5.1 +8/GD/Graph/histogram.pm line 119, <INPUT> line 1. Use of uninitialized value $max in numeric le (<=) at /Library/Perl/5. +18/GD/Graph/histogram.pm line 122, <INPUT> line 1. Use of uninitialized value in string eq at /Library/Perl/5.18/GD/Graph +/histogram.pm line 42, <INPUT> line 1. Use of uninitialized value in subtraction (-) at /Library/Perl/5.18/GD +/Graph/histogram.pm line 59, <INPUT> line 1. Use of uninitialized value in addition (+) at /Library/Perl/5.18/GD/Gr +aph/histogram.pm line 59, <INPUT> line 1. Use of uninitialized value $filename in concatenation (.) or string at + /Users/Joshua/eclipse-workspace/PlottingPoints/Histogram line 40, <I +NPUT> line 1. No such file or directory at /Users/Joshua/eclipse-workspace/PlottingP +oints/Histogram line 40, <INPUT> line 1.

2018-07-20 Athanasius added code tags around error messages


In reply to Histogram Creation by Galahad

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!
  • 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:
    & &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.