in reply to Passing anon sub as param
(1) To make traverse reusable. You can change the action taken for every node without editing traverse. You can make traverse do two different things without writing two different versions of it. As BrowserUK's mentioned in his post, "By passing a sub to the traverse routine you can make it do things other than just printing."
(2) Same answer as above. Both will work,
(3) The sub needs to be provided the node on which it is to perform an action. Normally, the node would have been passed as a parameter. This alternate way is a bit more concise and has less overhead.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Passing anon sub as param
by punkish (Priest) on Jul 28, 2005 at 20:36 UTC | |
by fishbot_v2 (Chaplain) on Jul 28, 2005 at 20:54 UTC | |
by ikegami (Patriarch) on Jul 28, 2005 at 20:56 UTC | |
by GrandFather (Saint) on Jul 28, 2005 at 20:52 UTC |