Do you know where your variables are? | |
PerlMonks |
Re: no visibility to global hashref ?!?by Laurent_R (Canon) |
on Jul 20, 2014 at 09:11 UTC ( [id://1094366]=note: print w/replies, xml ) | Need Help?? |
When you are entering the measureFieldLength subroutine, you are copying the argument $allActivity_fieldLength_hashref (which is undef at this point) into the $tableName_fieldLength_hashref variable. You are then populating the hash referred to by $tableName_fieldLength_hashref, but the global $allActivity_fieldLength_hashref variable remains undef throughout the process.
You might want to return $tableName_fieldLength_hashref to the caller function when exiting the measureFieldLength and modify this function to assign that return value to the $allActivity_fieldLength_hashref global variable. Or, alternatively, work directly on the global variable within the subroutine (although this is far from being clean). In brief, you should either decide your variables are global and, in this case, you should not pass them around as arguments (this is not the best solution, but at least it would probably work the way you want), or you don't make them global and pass them around as arguments and return values (which would be considered a better solution). But don't mix the alternatives, that's what is getting you into trouble. Update: I would add that your program is difficult to read and to understand because your variable and function names are too long and too similar, and using CamelCase doesn't make your identifiers easy to read. Also, why are you using subroutine prototypes? Are you sure you understand and need them?
In Section
Seekers of Perl Wisdom
|
|