and...@geekuni.com (Andrew Solomon) writes:

> Hi Harry
>
> What do you want your code to do?
>

Devise a simple test script the counts the number of directories in a
hierarchy (This is building toward a more complex script in the end).
But taking small steps in an effort to really understand what is
happening.

>>   find sub {
>>     return if -f;
>>     print "\$File::Find::dir<$File::Find::dir>\n";
>>   }, $d;

Seemed to me, would do that.  Skip -f type files and print all
directory names.

Instead I see:

>> Output:
>>   reader > ./tst.pl
>>   $File::Find::dir<./one>
>>   $File::Find::dir<./one>
>>   $File::Find::dir<./one/two>

That is the parent directory is printed twice, the second level is
printed as I'd expect. The third level is not printed at all.

I see on reflection that I should have just left any code concerning
-f files clear out and simply selected -d type files and printed them,
And more importantly changed what I'm printing... instead of
File::Find::dir what at first blush seemed like the right choice but
once you've selected only -d type then File::Find::name shows the
whole path: 

  find sub {
     if (-d) {
        print  "\$File::Find::name<$File::Find::name>\n";
     }
  }, $d;

Which does return what I would expect... so now I can build on that
and try to get a little closer to something I can use.

  $File::Find::name<./one>
  $File::Find::name<./one/two>
  $File::Find::name<./one/two/three>

I'm not really clear yet on why my first code did not cover all levels
of the hierarchy but the second stab does.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to