I have a program that takes a directory string, opens it and then reads the directory into an array. It then checks the filesystem objects to see if there is another directory that needs to be searched for files or if there are files. If the objects are files it places those filenames into another array. This array is then placed into a hash with two keys ROOT and FILES.

If there are no files the hash just contains ROOT with a value of "0". The value of ROOT is the directory that contains the files and FILES is a reference to the @files array. The hash is then returned and a refernce to it is placed into another array. Essentially that new array is the entire directory structure with Parent directories and Child files.

The problem is when I print the array there seems to be blank lines that I can't account for and don't know how their getting into my structure? Heres a snippet of code that does all this:

our @Search = ("/directory_2b_searched"); sub open_dir { ...Code to open and read directory... #Loop thru Directory objects foreach $object (@objects) { if (-d $path . $object) { push @Search, $path . $object; # It's a directory to be se +arched } else { push @files, $object; # It's a file } } # If @files is empty return %tree with 1 key if ($#>files > 0) { my %tree = (ROOT=>$path, FILES=>\@files); return %tree; } else { my %tree = (ROOT=>"0"); return %tree; } } for (@Search) { my %dir_tree = open_dir($_); push @dir, \%dir_tree if ($dir_tree{ROOT}); }

Before %dir_tree is pushed into the @dir array it is checked to make sure it has a TRUE value, which is why I put ROOT=>"0" so that it's evaluated as false. This works because I have no hash values with "0" just blank lines in my output. I just can't figure it out. Thanks

Updated: Also, when I print out the structure I print it out with ROOT a tab and then FILES. So I know that there seems to be a ROOT in a hash with no value and a FILES with no value.


In reply to Problems with blank lines by jakeeboy

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.