I frequently read nodes criticising global variables, and I think I might be guilty of using one, but I'm not sure:
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.