wow... this is impressive, i like it!

here's some thoughts, i don't think they're that great, but some things for you to think about.
for my $i ( 0 .. $#$sqldata ) { if ($sqldata->[$i]{under} == 0 ) { push (@tree, $sqldata->[$i]); } for my $j ( 0 .. $#$sqldata ) { if ($sqldata->[$j]{under} == $sqldata->[$i]{pageid} && $sqldata- +>[$j]{level} == 2) { $sqldata->[$j]{tab} = 1; push (@tree, $sqldata->[$j]); for my $k ( 0 .. $#$sqldata ) { if ($sqldata->[$k]{under} == $sqldata->[$j]{pageid} && $sq +ldata->[$k]{level} == 3) { $sqldata->[$k]{tab} = 2; push (@tree, $sqldata->[$k]); for my $l ( 0 .. $#$sqldata ) { if ($sqldata->[$l]{under} == $sqldata->[$k]{pageid} +&& $sqldata->[$l]{level} == 4) { $sqldata->[$l]{tab} = 3; push (@tree, $sqldata->[$l]); } } } } } } }
i didn't look at this too much, but it looks like you do the same thing a bunch of times nested. this may be a prime place for some recursion!



for ( 0 .. $#tree ) { if ( $tree[$_]{tab} == 1 ) { print "---" } if ( $tree[$_]{tab} == 2 ) { print "------" } if ( $tree[$_]{tab} == 3 ) { print "---------" } print $tree[$_]{pagename}."<br />"; }
can be changed to:
for ( 0 .. $#tree ) { print "---" x $tree[$_]{tab}; print $tree[$_]{pagename]."<br />"; }


i like this program, i'm very impressed. i would say with a little recursion and a little abstraction on the second part (instead of testing each value and printing the number of lines according to the test) you should be able to make this so you can have more than just 3 or 4 levels too.

In reply to Re: Cleaner code to build hierarchical display of page names by mrborisguy
in thread Cleaner code to build hierarchical display of page names by bradcathey

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.