bpthatsme has asked for the wisdom of the Perl Monks concerning the following question:
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]; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem populating Hash (I think?)
by kcott (Archbishop) on Feb 09, 2012 at 02:23 UTC | |
|
Re: Problem populating Hash (I think?)
by GrandFather (Saint) on Feb 09, 2012 at 02:47 UTC | |
|
Re: Problem populating Hash (I think?)
by planetscape (Chancellor) on Feb 09, 2012 at 06:08 UTC | |
|
Re: Problem populating Hash (I think?)
by Marshall (Canon) on Feb 09, 2012 at 05:30 UTC | |
|
Re: Problem populating Hash (I think?)
by jwkrahn (Abbot) on Feb 09, 2012 at 07:00 UTC | |
by bpthatsme (Novice) on Feb 10, 2012 at 00:57 UTC | |
by bpthatsme (Novice) on Feb 10, 2012 at 01:07 UTC | |
|
Re: Problem populating Hash (I think?)
by NetWallah (Canon) on Feb 09, 2012 at 02:27 UTC |