I wrote a project a while ago, to allow web-based discussions with threading of user comments. It was deficient in more ways than I care to list, and I'm thinking of a major rewrite/overhaul. For the threading, I used this code (it links to a MySQL database which stored the discussions):

sub getarticles { + my $article = shift; + my $query = qq(SELECT reply FROM replies WHERE article=$articl +e ORDER BY reply); my $sth = $dbh->prepare($query); + $sth->execute; + $sth->rows or return 0; + while (my $reply = $sth->fetchrow) { + my $query = qq(SELECT timestamp, subject, author FROM +article WHERE id=$reply); my $sth = $dbh->prepare($query); + $sth->execute; + my ($timestamp, $subject, $author) = $sth->fetchrow; + $sth->finish; + ( code to show the retrieved items as html, snipped ) $indent++; + &getarticles($reply); + $indent--; + } + $sth->finish; + return; + }

This produces output like this:

First comment First reply Second reply First reply to Second reply above Second reply to Second reply above Third reply

I would like to know how I could produce output similar to the unix "tree" program, ie with lines to indicate relationships between nodes:

First comment `-------First reply `-------Second reply | `-------First reply to Second reply above | `-------Second reply to Second reply above `-------Third reply
And any other observations you might care to make. TIA.

2001-03-04 Edited by Corion : Changed <PRE> tags to <CODE> tags.


In reply to Graphical Hierarchical Tree by yojimbo

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.