Parsing Path Data into Tree Structure

From: Dale (desau_at_aisc.ac.cy)
Date: 04/30/04


Date: 30 Apr 2004 00:23:02 -0700

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



Relevant Pages

  • Re: I want a perl script for?
    ... There exists a .zip which contains folders and file. ... And search for .c files in them and list them in separate text file. ... I think that, since you are new to Perl, it would be better to extract the ... makefile in them. ...
    (perl.beginners)
  • Re: Exchange 2007 public folder error
    ... CN=Your Exchange Org ... highlight CN=Public Folders and select properties. ... By default you can only have 1 MAPI PF Tree. ...
    (microsoft.public.exchange.admin)
  • Re: Folders-type menu. Problems ??
    ... it has all worked perfectly and the client is about to ... > folders opening to pages where files cannot be found, ... On several machines we have opened the tree ... > click to the link it shows "done" but the link won't load. ...
    (comp.lang.javascript)
  • Folders-type menu. Problems ??
    ... it has all worked perfectly and the client is about to ... folders opening to pages where files cannot be found, ... On several machines we have opened the tree ... click to the link it shows "done" but the link won't load. ...
    (comp.lang.javascript)
  • Re: Inside-out objects are slow! (or how to accelerate OO Perl?)
    ... The thing is what is pathological for Perl? ... My module takes approx 1 sec to execute (on ... Tree ... profile". ...
    (comp.lang.perl.misc)