Don't ask to ask, just ask | |
PerlMonks |
Passing anon sub as paramby punkish (Priest) |
on Jul 28, 2005 at 20:06 UTC ( [id://479117]=perlquestion: print w/replies, xml ) | Need Help?? |
punkish has asked for the wisdom of the Perl Monks concerning the following question:
I was recently tackling creating a hierarchical tree of nodes, as in a nested, threaded, discussion list. My data structure would be like (ultimately in a db table) --
I would create a sub foo, that would take as input a r_to, traverse the AoH, print out the line, then call itself with the c_id of that line. The result would be
I wrote a bunch of code, messed it up, and then went about looking for examples. I found the oh so wise BrowserUk's contribution in the node Re: Cleaner code to build hierarchical display of page names funnily called traverse! A little bit of editing, and I had the following working beautifully --
Then I started wondering why the anon sub was being passed as a param to the sub traverse. Not knowing why, I decided to remove it like so.
And that too worked beautifully. So, I ask the following --
In anticipation...
--
when small people start casting long shadows, it is time to go to bed
Back to
Seekers of Perl Wisdom
|
|