Good Afternoon, evening, morning, and all other times of day Monks!

This is my first post here and I come to you with an issue regarding the use of a hash of arrays.

I have searched around significantly and used all of the debugging available in my arsenal to attempt to solve this issue, but remain stumped.

That said I come to you humbly hoping for answers. The below code is a portion of code written to tear apart csv formatted HTML (that is achieved successfully earlier in the script via regex). However I continue to receive errors regarding uninitialized values, beginning with the first @values line in the for loop. I know that this means that I have not defined the value, but I am also unsure on how to do this while populating an array. Any guidance will be vastly appreciated!

Best!

bp

PS- My apologies if this is a double post, I wanted to make sure the post was written under my username as opposed to an anonymous user!

my $stats = $htmlcontent; @rows = split(/\n/,$stats); #prints the cleaned up data after dumping it to an array #foreach (@rows) { # print "$_\n"; #} #Make sure 'good' data is pulled if ( $rows[0] !~ /Function Name/ ) { $np->nagios_exit("UNKNOWN", "Can't find csv header!\n"); exit $ERRORS{"UNKNOWN"} } #get number of rows after data cleanup $rowcount = scalar(grep {defined $_} @rows); #foreach (@values) { # print "$_\n"; #} #die; my @fields = (); @fields = split(/\,/,$rows[0]); @values = (); my %stats = (); for ( my $i = 1; $i <= $rowcount; $i++ ) { @values = split(/\,/,$rows[$i]); #print "this is row [$i] : $rows[$i]\n"; if ( !defined($stats{$values[0]}) ) { $stats{$values[0]} = {}; } if ( !defined($stats{$values[0]}{$values[1]}) ) { $stats{$values[0]}{$values[1]} = {}; } for ( my $x = 2,; $x < $#values; $x++ ) { # $stats{pxname}{svname}{valuename} $stats{$values[0]}{$values[1]}{$fields[$x]} = $values[ +$x]; } }

In reply to Problem populating Hash (I think?) by bpthatsme

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.