in reply to Setting Global Variable in Sub
Is there any chance you could post your code to this? It's a little difficult to tell what you mean without seeing it, to be honest.
If you're scoping the variable with 'my' in order to get your script to work under 'use strict' then yes, $main::COOKIE_ID would help. 'My' stops the variable existing after the routine exits, but $main::COOKIE_ID is the global variable.
A cleaner way would be to return the values to the main routine, so something like the following would happen... again tricky to show without knowing what this is being draped around, but here goes.
use strict; ... # Call the subroutine to get the info. my ($cookieid, $cookiename) = getCookieInfo(); ... # The subroutine itself. sub getCookieInfo { # Keep these localised... my ($cookieid, $cookiename); ... # ... and then return them. return ($cookieid, $cookiename); }
Still possibly cleaner ways would be to return hashes, with the keys of id, name etc and the suitable values. Slightly less transparent than the above though so I'll stick to just describing the above, but easy enough to get to here from there. This is especially useful when you're getting a lot of return values in my experience.
|
|---|