Here's the general process.
Go through all of the subroutines and ensure that every global variable that should be a parameter to the function is actually passed as a parameter. Also ensure that all return information from the function is returned via return.
You now have a whole load of parts that you can prove individually must work, if their inputs are sane. This is good.
If you're confused about how to keep information persistent between subroutine calls, and you "outgrow" simple use of "return", here is my advice: Pass a reference to a data structures holding the information you want as the first argument to a function. eg:
sub xfer_ssh { my ($xferSessionInfo, @other_args) = (@_); # set something in %xferSessionInfo - note use of the # -> operator to dereference. $xferSessionInfo->{foo} = "bar"; # exactly the same thing, written a way that some find # easier to grok. ${ $xferSessionInfo }{foo} = "bar"; return "ok"; } my %xferSessionInfo; &xfer_ssh(\%xferSessionInfo, @other_args); print $xferSessionInfo{foo}; # prints "bar"
Group your functions by what you are expecting to use as this first argument. eg, all of the functions that deal with "%xferSessionInfo" hashes together. Where possible, only make changes to the state variable that is the first argument to the function.
Practice this coding style for a while; it should be well within your reach. After you have mastered this technique, then read the perltoot man page (I wouldn't recommend reading it just yet).
In reply to Re: persistent variables between subroutines (long)
by mugwumpjism
in thread persistent variables between subroutines (long)
by Tuna
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |