LPC2010 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All- I have the following problem. A top level directory /clients and there are a number of directories beneath (and further subdirectories) I need to produces the following HTML:
<ul class="navigation-explorer"> <li><div class="icon" id="menu/menuitem[0]"><a class="navigatio +n-node" href="#" onclick="top.customnavhandler('menu/menuitem[0]'); r +eturn false;">Business</a></div></li> <div class="navigation-layer"> <ul class="navigation-explorer"> <li><div class="icon" id="menu/menuitem[0]/menuitem[0]"> +<a class="navigation-node" href="#" onclick="top.customnavhandler('me +nu/menuitem[0]/menuitem[0]'); return false;">Small Business</a></div> +</li> <div class="navigation-layer"> <ul class="navigation-explorer"> <li><div class="icon" id="menu/menuitem[0]/menuit +em[0]/menuitem[0]"><a class="navigation-node" href="#" onclick="top.c +ustomnavhandler('menu/menuitem[0]/menuitem[0]/menuitem[0]'); return f +alse;">Products & Services</a></div></li> <li><div class="icon" id="menu/menuitem[0]/menuit +em[0]/menuitem[1]"><a class="navigation-node" href="#" onclick="top.c +ustomnavhandler('menu/menuitem[0]/menuitem[0]/menuitem[1]'); return f +alse;">Solutions</a></div></li> <li><div class="icon" id="menu/menuitem[0]/menuit +em[0]/menuitem[2]"><a class="navigation-node" href="#" onclick="top.c +ustomnavhandler('menu/menuitem[0]/menuitem[0]/menuitem[2]'); return f +alse;">Wireless</a></div></li> <div class="navigation-layer"> <ul class="navigation-explorer"> <li><div class="icon" id="menu/menui +tem[0]/menuitem[0]/menuitem[2]/menuitem[0]"><a class="navigation-node +" href="#" onclick="top.customnavhandler('menu/menuitem[0]/menuitem[0 +]/menuitem[2]/menuitem[0]'); return false;">Phones</a></div></li> </ul> </div> </ul> </div> </ul> </div> </ul>
I was hoping there is a quick Perl script that will recurse through these directories and be able to dynamically determine the depth and produce the required levels. Each lower level requires the fullpath of it's parents, and there is an XML file in each folder with some more information to be parsed. I think I can figure that one out once the recursion code is working. Might anyone be able to shed some light on this one? Thanks a bunch!!!

Replies are listed 'Best First'.
Re: Dynamic list of HTML
by roboticus (Chancellor) on Dec 02, 2010 at 02:59 UTC

    LPC2010:

    I'd suggest using File::Find to recurse through the directories. It provides a wanted hook you can use to collect the filenames, as well as a preprocess and postprocess hook for entering and exiting directories. Just emit the appropriate HTML in the various locations, and you should have a fine start.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Dynamic list of HTML
by ww (Archbishop) on Dec 01, 2010 at 23:53 UTC
    We don't hand out "quick Perl script(s)" as a reward for posting a question without any evidence of effort to solve a problem.

    We do, however, go to considerable lengths to assist those who take a stab at their problems and show their efforts.

    Absent that, a few hints: Super Search for recurse, 'file path' or subdirectories; search for possibly relevant modules using PPM (if on windows/ActiveState] or search.cpan.org/ (the docs will likely provide enough info to make selections; using one or more modules from CPAN probably the most reliable way for you to work) and maybe even a tut or two in Tutorials.

Re: Dynamic list of HTML
by Anonymous Monk on Dec 02, 2010 at 03:13 UTC
    See tabs to html list, thats recursion (simulated).
    • Replace while ( readline $fh ) with something involving File::Find::Rule
    • Replace $curr = to count depth based on the path (easier with Path::Class)
    • If keeping $count isn't sufficient, maybe adapt htmltreexpather.pl to generate your id/menu attribute
    • ...
    • profit