Parsing Path Data into Tree Structure

D

Dale

I'm creating a simple web-based image management tool and am looking
for a way of creating a tree structure to display folders and titles
of images contained in those folders. What I am trying to do is take a
very plain text string describing a path and parse that into a tree to
display in html.

My incoming data via DBI looks like this

/folder 1/image1.jpg
/folder 1/subfolder 1/image2.jpg
/folder 1/subfolder 1/subsub folder 1/image3.jpg
/folder 1/image4.jpg
/folder 2/image5.jpg
/folder 1/subfolder 2/image6.jpg
etc...

and I want to output sort of like

folder 1
-> subfolder 1
-> -> subsubfolder 1
-> -> -> image3.jpg
-> -> image2.jpg
-> subfolder 2
-> -> image6.jpg
-> image1.jpg
-> image4.jpg
folder 2
-> image5.jpg

though with lots of pretty icons and collapsing row structures (which
I won't bore you with since its jscript and not perl)

So my questions:

1. Is there a module available anywhere that already does this?
2. If not, I can work with one of the Tree:: modules and need ideas on
how to parse my paths into the required structure. (ie how to extract
the parent/child node relationships correctly)
3. And if there is another better way of accomplishing this whole task
I would love to hear about it.

* and for those list purists who are wondering where the perl is in
this question, my whole app is perl, so am looking for perl answers
using regexes, splits, and arrays or hashes, etc.

Many thanks in advance for any guidance

DRE
 
D

David K. Wall

Dale said:
What I am trying
to do is take a very plain text string describing a path and parse
that into a tree to display in html.

My incoming data via DBI looks like this

/folder 1/image1.jpg
/folder 1/subfolder 1/image2.jpg
/folder 1/subfolder 1/subsub folder 1/image3.jpg
/folder 1/image4.jpg
/folder 2/image5.jpg
/folder 1/subfolder 2/image6.jpg
etc...

and I want to output sort of like

folder 1
-> subfolder 1
-> -> subsubfolder 1
-> -> -> image3.jpg
-> -> image2.jpg
-> subfolder 2
-> -> image6.jpg
-> image1.jpg
-> image4.jpg
folder 2
-> image5.jpg


Search Google groups for Message-ID
<[email protected]> and you'll find an
algorithm you can adapt.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top