I have directory information stored in a database that I need to build a report on. Each directory is stored with the complete path (/root/foo/bar/lastdir) and there is a lot of duplication because of this. I would like to be able to sort this data and print it out in a simple easy to read structure (besides the complete path for every item).
Here is the some sample data:
0555-DDBB/AirPhotos 
0555-DDBB/AirPhotos/AP Labels 
0555-DDBB/AirPhotos/new database 
0555-DDBB/FOO M 
0555-DDBB/FOO M/0555-055-01 Site/Photos 
0555-DDBB/FOO M/0555-055-01 Site/Photos/Digital 
0555-DDBB/FOO M/0555-055-01 Site/Photos/PhotoList 
0555-DDBB/FOO M/0555-055-01 Site/Reports/Summary 
0555-DDBB/FOO M/0555-055-01 Site/Reports/Daily 
0555-DDBB/FOO M/0555-055-02 Design 
0555-DDBB/FOO M/0555-055-02 Design/photo 
0555-DDBB/FOO M/0555-055-02 Design/photo/Ortho 
0555-DDBB/FOO M/0555-055-02 Design/Correspondance 
0555-DDBB/FOO M/0555-055-02 Design/Drafting 
0555-DDBB/FOO M/0555-055-02 Design/Drafting/DWG
I would like to be able to print out a directory structure something like:
0555-DDBB
  AirPhotos
    AP Labels
    new database
  FOO M
    0555-055-01 Site
      Photos
        Digital
        PhotoList
      Reports
        Summary
        Daily
    0555-055-02 Design
      photo
        Ortho
      Correspondance
      Drafting
        DWG
Basically remove the duplication, and some indenting to show levels ofr the directory tree. But I'm having trouble thinking of a way to store it so I can print it out. I played with some nested hashes, but it seemed to get ugly after I had 6 or 7 levels of directories to sort ($paths{$dir1}{$subdir1} $paths{$dir1}{$subdir2} etc etc). I have each directory in an array and I can split on '/', but from there I'm lost.
@dirs = ( # list from above ); foreach my $dir (@dirs) { my @singleDirs = split(/\//, $dir); # stuck }
How can I store all the info (direcotry names and location) and then print out as above? I'm just stuck for an idea - can anyone stear me in the right direction? Thanks,

djw

In reply to organizing directory path data by djw

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.