http://www.perlmonks.org?node_id=501932

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


Greetings Monks,
I've ran into a small situation and here I am to seek the help of you esteemed.

This is the requirement - to emulate a windows-explorer like directory tree structure (using perl, ofcourse)
Oh, and the directories that we're talking of is from a linux box.
So, considering I have a recursive directory listing in the form like this:
examples/html: examples/html/bars: examples/html/headers: examples/html/links: examples/html/lists: examples/html/menus: examples/html/rgb: examples/html/tables: examples/ps: examples/ps/marks: examples/splash: examples/splash/dropbox: examples/splash/frame: examples/splash/hair: examples/splash/icon: examples/splash/menu: examples/splash/menubar:
..the output that is required is a kind like this:
<ul> <li><a href="examples/">examples/</a> <ul> <li><a href="examples/html">html/</a> <ul> <li><a href="examples/html/bars/">bars</a></li> <li><a href="examples/html/headers/">headers</a></li> <li><a href="examples/html/links/">links</a></li> <li><a href="examples/html/lists/">lists</a></li> <li><a href="examples/html/menus/">menus</a></li> <li><a href="examples/html/rgb/">rgb</a></li> <li><a href="examples/html/tables/">tables</a></li> + </ul> </li> <li><a href="examples/ps/"">ps/</a> <ul> <li><a href="examples/ps/marks">marks</a></li> </ul> </li> <li><a href="examples/splash/">splash/</a> <ul> <li><a href="examples/splash/dropbox/">dropbox</a></li +> <li><a href="examples/splash/frame/">frame</a></li> <li><a href="examples/splash/hair/">hair</a></li> <li><a href="examples/splash/icon/">icon</a></li> <li><a href="examples/splash/menu/">menu</a></li> <li><a href="examples/splash/menubar/">menubar</a></li +> </ul> </li> </ul> </li> </ul>

The Unordered-List will then be used along with a JavaScript code and a Style Sheet making it a tree-like expandable struture.
I'm finding the making of the unordered list a bit complicated - from the raw data. (Array of arrays, multiple arrays etc.)
And this is only the directories and we aren't listing any files at all.

Any help is appreciated.

Thanks,
Rupesh.