|Don't ask to ask, just ask|
Re: Predefining sub Parametersby techcode (Hermit)
|on Jun 22, 2005 at 23:41 UTC||Need Help??|
While most of people gave you various (and very good) responses. I'd like to comment on this.
I really like this way it's done in Perl. Sure it takes a bit of time to adjust to it - but once you do that. It comes somehow naturally.
Also - once I discovered how hashes are great (before Perl I only used C on university, and some Basic variants like M$ VB and old Amiga AMOS on my own) I started almost just using them :)
They are so great because many of the modules use them, and at the end of the day, my jobs ends up in passing references from one module to other :)
In your case (actually in almost any case) I would probably use something like:
Or other similar option: < EDIT: As sugested a little earlier >
Good thing about this, is that when you write the sub, you don't need to set the local variable for each sent parameter. The order of parameters also isn't important, but caller needs to know exact names that you use through the sub. IMHO I just like this way better.
While you can use any of the above, first one (passing reference) should be better in case you have many variables (in this case tree, since we pass array_ref). I would suggest you actually use just it.
I also noticed that many CPAN modules use this for configuration type method calls.PS. This way you predefine the names of the variables but not their placing in sub call :)