Basilides has asked for the wisdom of the Perl Monks concerning the following question:
I'm traversing a Binary Search Tree looking for a particular value, but there could be more than one node where it occurs...So, I set up an array in my main package, and pass a reference to it to the recursive traversal subroutine in the Tree object. This traverses the whole tree, and every time there's a match, pushes the current node to this array.
So that's it: one object is pushing values to an array in another (in real life the call isn't from main). Incidentally, it works. But I have a feeling I'm breaking some fundamental OO rules, or maybe this is an example of a ghastly global variable? I've even read nodes saying that I shouldn't be passing by reference at all, but I'm not too fussed about that.
edited: Mon Jul 1 18:48:44 2002 by jeffa - title change
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Global variables
by Abigail-II (Bishop) on Jul 01, 2002 at 16:19 UTC | |
|
Re: Global variables
by vladb (Vicar) on Jul 01, 2002 at 15:55 UTC | |
|
Re: Global variables
by broquaint (Abbot) on Jul 01, 2002 at 15:49 UTC | |
|
Re: Global variables
by demerphq (Chancellor) on Jul 01, 2002 at 17:13 UTC | |
by broquaint (Abbot) on Jul 01, 2002 at 17:37 UTC | |
|
Re: Global variables
by Aristotle (Chancellor) on Jul 01, 2002 at 16:27 UTC |