Hi Monks, I've been playing with File::System for some scripts I need to create and trying to get hash of hashes made as a representation of the directory/file structure I'm using. The basic layout is:

$root is an object set to some test directory, $path=/root/Code/Test in this case via the File::System->new('Real', root=> $path);
I would like the script to go through the various directories and files it can find and stick them into hashes.
I run into some issues at first because the objects returned by File::System contain extra data that will throw errors if I try to use methods like is_container or has_children against them. I finally got around it by using ->lookup to get a File::System object for the key I want test, and using a technique used in the intermediate perl book for recursive searches on file systems, I was able to get a hash of hashes that looks almost right, but I think I'm doing something wrong because where I expect to see undef's I get => {} which doesn't seem right to me.

The subroutine I use is as follows:
sub paths { my $paths_ref = shift; while ( my ($k,$v) = each %$paths_ref) { my $l=$root->lookup($k); if ($l->is_container) { if ($l->has_children) { foreach my $c($l->children) { my $c_ref = {}; $paths_ref->{$c} = $c_ref; paths($paths_ref->{$c}); } } else { $paths_ref->{$k} = undef; } } else { $paths_ref->{$k} = undef; } } }

My data dump looks like this:
$VAR1 = { '/' => '/', '/S1_A1/tmp/test' => {}, '/S1_A2/tmp' => {}, '/S1_A1' => {}, '/S1_A1/tmp/test1' => {}, '/test' => undef, '/S1_A1/tmp/test2' => {}, '/S1_A3' => {}, '/S1_A1/tmp' => {}, '/S1_A2/test' => {}, '/S2_A2' => undef, '/S1_A3/tmp' => {}, '/S1_A2' => {}, '/S1_A3/tmp/test' => undef, '/S2_A1' => undef };


test, test1 and test2 are files
S*_A* and tmp are directories

I just want to make sure things look ok since I'm still newbish with some of this stuff.
Thanks.
-C

In reply to File::System recursion by koaps

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.