cens has asked for the wisdom of the Perl Monks concerning the following question:
The problem is I am not able to navigate through the different subdirectories at all, so I only pull out the top level of files. I am basically opening the parent, reading everything into an array, and testing to see if it is a directory or a file.
If it is a directory, I want to open that file up and look inside. I thought that I could call the same subroutine from itself to continue the navigate down, but I can't seem to get that part working. This is what I am doing so far:
I thought I could do this and think that the problem may be in the reassign of the directory handle, but after trying a few workarounds, I am a little stumped. Any advice/jeering would be appreciated. Thanks a lot.sub readindirs { my ($dirname) = @_; opendir(NEWDIR, $dirname) or die $!"; @newfiles = grep { $_ ne '.' and $_ ne '..' } readdir NEWDIR; closedir NEWDIR; $length = scalar(@newfiles); for ($i = 0; $i < $length; $i++) { if (opendir(DIR1, $newfiles[$i])) { #this is where i want to re-call the sub &readindirs($newfiles[$i]); } else { &parse_sub_routine } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Navigating Dierctories Recursively
by sauoq (Abbot) on Oct 16, 2003 at 20:27 UTC | |
|
Re: Navigating Dierctories Recursively
by dragonchild (Archbishop) on Oct 16, 2003 at 20:30 UTC | |
by cens (Novice) on Oct 16, 2003 at 21:05 UTC | |
by dragonchild (Archbishop) on Oct 16, 2003 at 21:32 UTC | |
by cens (Novice) on Oct 16, 2003 at 21:41 UTC | |
|
Re: Navigating Dierctories Recursively
by vek (Prior) on Oct 16, 2003 at 21:39 UTC | |
|
Re: Navigating Dierctories Recursively
by data64 (Chaplain) on Oct 17, 2003 at 01:28 UTC |