Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to no visibility to global hashref ?!?

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?

Replies are listed 'Best First'.
Re^2: no visibility to global hashref ?!?
by Anonymous Monk on Jul 21, 2014 at 19:36 UTC
    I decided to go with returning the hashref being populated as a return value from measureFieldLength. Thanks for the replies, kerchunk

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1094366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found