Okay, I think this should not be too tough, but I am really messing it up. I have a directory with multiple subdirectories and files therin. Inside each of those subdirectories, I have even more files and subdirectories, ad nauseam. Each time is see a file, I want to sent it to a new subroutine.
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:
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
}
}
}
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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.