in reply to Re^2: Hash confusion ?!
in thread Hash confusion ?!
The process() sub is altering a global hash, so everything else in the script has access to the updated hash data simply by using the same global. The fact that process() is returning a reference to that hash is irrelevant, because you never actually use the return value anyway.
Using a subroutine to alter global data this way can often make the code harder to understand and harder to maintain. It also makes it easier to create bugs that are hard to track down, because any subroutine could create unintended side effects by altering globals when you didn't really intend to do that.
For scripts of limited complexity (like yours, if it were written sensibly), using globals could make things seem simpler overall, and that's fine; but if you ever decide to re-use this or that subroutine from the script, the presence of globals inside the subs will make this harder than it should be.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |