Hmmm... I tried fixing the code as you suggested, and ended up with the same problem. I goes into one directory and no further than that level. I am trying to avoid using the modules, because I am on the road and need to email this to someone who does not really know perl. I am getting the problem where it reads in the directory the first time, and every other time treats the directory like a file (as if the if (-d $name) piece was failing).

I am running the following:

#!/usr/bin/perl; use strict; sub readindirs { my ($dirname) = @_; print "$dirname -> dirname \n"; opendir(NEWDIR, $dirname) or die $!; my @newfiles = grep { $_ ne '.' and $_ ne '..' } readdir NEWDIR; closedir NEWDIR; foreach my $name (@newfiles) { if (-d $name) { print "name:: $name \n"; readindirs($name); } else { print "parse file : $name \n"; #&parse_file($name); } } } &readindirs('.');

Which results in this:

. -> dirname name:: about about -> dirname parse file : aic3.pl parse file : contact parse file : coredocs parse file : footer.inc parse file : index.html parse file : nav.js parse file : organization parse file : overview parse file : programs parse file : rightnav.inc parse file : template.html parse file : top.inc parse file : about2.zip parse file : aic.pl parse file : aictemp.pl
Of which contact, coredocs, organization, overview, and programs are directories.

I am doing this on a windows distr. and am not really a windows person, I know that there are a few differences between *nix and windows perl, is this one of them? The other thing, which is purely for my own interest, is how is  if (-d $name) better/worse than (opendir(DIR, $name)).

Thanks a lot for your help. If I can't figure it out soon, I think that I will go to the modules.


In reply to Re: Re: Navigating Dierctories Recursively by cens
in thread Navigating Dierctories Recursively by cens

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.