Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Build tree data structure from DB (flat) data; function golf

by imp (Priest)
on Sep 02, 2006 at 05:33 UTC ( #570858=note: print w/ replies, xml ) Need Help??


in reply to Build tree data structure from DB (flat) data; function golf

I like the closure approach suggested by stvn. It comes with a small performance penalty because of all the function calls (7-20% depending on the dataset and spread), but it makes the code much easier to read/maintain.

On a related note - it would be good to add some documentation that describes your strategy. It isn't immediately apparent, and I had to re-read the code a few times before it was clear.

Found one problem: the following line should test whether $last_key is defined, to avoid problems when your data contains an empty string or '0'.

if ( $last_key and ( $last_key ne $_->{ $key_name } ) ) {


Comment on Re: Build tree data structure from DB (flat) data; function golf
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://570858]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-07-05 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls