Hi again!
Okay so I'm writing a CGI/Perl program (Object-Oriented Style) for some purpose. I use a tree-like structure in my program which, at certain situations, loads information from a database.
Foreach database entry, the program adds it to the tree, but only if its parent was already found (and added). If not, it pushes it into a buffer array.
In the end of the database reading, another method iterates over the buffer and adds the entries in it to the tree. Once again, this method also adds only if the parent was already added. So if an item from the buffer is added to the tree, it is also deleted from the buffer, and the method runs recursively with the changed buffer.
When calling the method, the program enters an infinite loop. I thought the recursion was the cause of it, so I deleted it to verify it, and it wasn't. It did the same thing again.
Anyway, the code looks like this (Recursion call commented out:
sub _addbuf {
my ($class, $buffer) = @_;
my $args = shift @$buffer;
if (SOMECLASS->exists($args->{parent}) {
my $new = SOMECLASS->new($args);
} else {
push(@$buffer, $args);
}
#SOMECLASS->_addbuf($buffer);
}
That's it. For some reason, the program enters an infinite loop, and I have no idea why.
Any help grately appreciated,
Ido Perelmutter.
-------------------------
Live fat, die young
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.