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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.