(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.
In reply to Re: Passing anon sub as param
by ikegami
in thread Passing anon sub as param
by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |