you're trying to build a tree of objects, right? The others are quite right to say that there isn't enough information here to diagnose your particular problem, but that's ok because there are plenty of more general problems to consider.
you seem to be using oop structures in a rather procedural way, and therefore missing several of their main benefits, not least ease of debugging. If you find yourself doing something complicated to an object from the outside, it's usually a mistake. Here the tree climbing subs should almost certainly be method calls of the $item, with the logic and especially the sql tucked away inside the object class. If i were you i'd get rid of the whole build_tree_for_cid machinery and put that code in an $item->children method, or some equivalent, depending on what you're going to need to do with it.
Perhaps a bit of time with perltoot and thedamian wouldn't hurt...
But perhaps it doesn't matter. You seem to be handrolling a way of mapping database records onto perl objects, and you really don't have to do that. There are several well-established systems that will do nearly all the work for you. Class::DBI is a favourite of mine (to the extent that i rarely seem to talk about anything else here), but tangram, alzabo, SPOPS and some of the DBIx family all have their adherents.
And a style point, while i'm being impertinent. A variable called $item or @retval tells us nothing about what it contains or why, and will tell you just as little in six months time when you want to update the code. Something simple like return @children; will save you minutes when you need them most. The same goes for values like the -1 you're using for item->type. A named constant like $item->type(PERSON) will make for more readable code.
(But anyway: should you really be typing the item? better in the long run to have an object class for each type and method calls that capture their relationships. Probably.)
Readable code isn't just a style prejudice. it saves on documentation and debugging time, and makes it much easier to get answers in places like this.
...hunts around in bookmarks... your best step now might be to read up on poop. persistent object-oriented perl. there's a good overview by Dave Rolsky at http://poop.sourceforge.net/, with links to a mailing list full of grate branes who are surprisingly willing to answer the silly questions with which i keep them supplied.
update: ps. on the other hand, in my_execer:
if (@row = $sth->fetchrow_array)
shouldn't that be while, not if?
In reply to Re: trouble... :)
by thpfft
in thread trouble... :)
by NodeReaper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |