in reply to Re: Passing anon sub as param
in thread 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.
Hence, I could have done the following just as well --
sub traverse { # do yer stuff _print($_); traverse(..); } sub _print { my ($node) = @_; print ' ' x $node->{dept}, $node->{c_id}, ': ', $_->{comm}, "\n"; }
Which, I did, and it also works. Hence, passing an anon sub as a param seems to be just a fancy way of doing what I already know MTOWODI, no?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Passing anon sub as param
by fishbot_v2 (Chaplain) on Jul 28, 2005 at 20:54 UTC | |
|
Re^3: Passing anon sub as param
by ikegami (Patriarch) on Jul 28, 2005 at 20:56 UTC | |
|
Re^3: Passing anon sub as param
by GrandFather (Saint) on Jul 28, 2005 at 20:52 UTC |