A nudge, a push, a kick, it's all good ;D
#!/usr/bin/perl -wl use strict; ## consider this a better way to go ## let %NODE be the representation of a typical record ## and in this case, our initial thread (aka a "root" node) my %THREAD= ( node_id => 1, root_id => 0, # 0 is the node_id of 'FooStuff', a "sect +ion" parent_id => 0, # well the parent of a "root" node is a +section content => "how do I echo a value to the screen?", title => "How do I echo a value to the screen?", ,); ## at this point you've *selected* all nodes whose parent ## is %THREAD, ie, node_id => 1 ## see, no need for recursive calls to the database ## it might be worth having a 'section' attribute ## if you want to be able to search through threads based on section my @NODES = ( \%THREAD, # therad is #1 { node_id => 2, root_id => 1, parent_id => 1, content => "i dunno", title => "re: How do I echo a value to the screen?" }, { node_id => 3, root_id => 1, parent_id => 1, content => "well you use the function print", title => "re: How do I echo a value to the screen?" }, { node_id => 6, root_id => 1, parent_id => 2, content => "don't say that", title => "re: re: How do I echo a value to the screen?" }, { node_id => 9, root_id => 1, parent_id => 6, content => "you guys are dumb", title => "re: re: re: How do I echo a value to the screen?" }, ,); print_kids(\%THREAD, 1, @NODES); exit; # not the most efficient, but it will do # (you're welcome to make with the improvements as always) sub print_kids { my ($NODE, $t, @NODES) = @_; for my $ix(0..scalar @NODES) { next unless exists $NODES[$ix]->{parent_id}; # due to sideffect of splice if( $$NODE{node_id} == $NODES[$ix]->{parent_id} ) { print "$t) ", " " x (4 * $t ), "( $NODES[$ix]->{node_id} ) ", $NODES[$ix]->{title}, "\n>>>>>>>>", ">" x (4 * $t ), " $NODES[$ix]->{content}\n"; my $N = splice(@NODES,$ix,1); print_kids($N, $t+1, @NODES); } elsif( $$NODE{node_id} == $NODES[$ix]->{node_id} ) { print "0) ", "( $NODES[$ix]->{node_id} ) ", $NODES[$ix]->{title}, "\n>>>>>>>>", ">" x (4 * $t ), " $NODES[$ix]->{content}\n"; my $N = splice(@NODES,$ix,1); print_kids($N, 1, @NODES); } } return undef; } __END__ $>perl thread.txt.pl 0) ( 1 ) How do I echo a value to the screen? >>>>>>>>>>>> how do I echo a value to the screen? 1) ( 2 ) re: How do I echo a value to the screen? >>>>>>>>>>>> i dunno 2) ( 6 ) re: re: How do I echo a value to the screen? >>>>>>>>>>>>>>>> don't say that 3) ( 9 ) re: re: re: How do I echo a value to the screen? >>>>>>>>>>>>>>>>>>>> you guys are dumb 1) ( 3 ) re: How do I echo a value to the screen? >>>>>>>>>>>> well you use the function print

 
______crazyinsomniac_____________________________
Of all the things I've lost, I miss my mind the most.
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"


In reply to (crazyinsomniac) Re: Sorting an Array of Hashes (AoH) by its keys as a threaded message by crazyinsomniac
in thread Sorting an Array of Hashes (AoH) by its keys as a threaded message by BMaximus

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.