in reply to Re^3: Hash of Arrays or Arrays of arrays? and how proceed?
in thread Hash of Arrays or Arrays of arrays? and how proceed?

I've got a compiling error on

$result{$database}{next}= $nextfield; $result{$database}{fields}= \@fields;

Use of uninitialized value in hash element

but I've declared "my %result;" at the start of the sub

Did I miss something? Did I need to declare $next and $fields?

Replies are listed 'Best First'.
Re^5: Hash of Arrays or Arrays of arrays? and how proceed?
by jethro (Monsignor) on Aug 02, 2011 at 11:13 UTC

    The uninitialized value in hash element(!) would be $database. In such cases it is a good debugging technique to add statements like the following to your code to observe what happens:

    use Data::Dumper; #at the start of the script ... print Dumper(\$database,\$nextfield,\@fields); $result{$database}{next}= $nextfield; $result{$database}{fields}= \@fi +elds; #<--- the problematic line

    A simple print "\$database is $database\n" would do as well, but Data::Dumper is to print for debugging like a lawnmower is to a scissor for cutting gras ;-).

    Look at the output and compare it to your expectations. Probably you will see an undef value printed for $database. Now you can retrace the steps, look how $database could get that value, insert "print Dumper..." statements where you think it could go wrong. Maybe it is a regex that didn't match anything or maybe you put a value in an array into $a[1] but not in $a[0], which would leave the first array value undefined...