recursivly matching string (a filename) in file, then testing said filename for same string, etc, etc...

Can't Post

I have a need to parse a file for "jsp:include=filename.inc", strip the filename out of the above include, and test it's existence, and if it exists, parse THAT file for the jsp:include filename string, etc etc recursively until all the includes in this "include tree" have been found (could be many layers deep, but prob not more than 6-10). I'd also like to keep track of the parent to child relationship somehow, so I know which include came from which parent in the tree.

I already have the regex for finding all the iterations of the jsp:include down, and for striping and cleaning the filename for further testing, but I am having trouble with the recursion through the tree of matches. I started this in bash but quickly realized I needed more than bash can give me, and I think Perl is probably the right tool, but I'm only so so with Perl.

If anyone could help point me in the right direction for how to handle the recursion part, I'd appreciate it. I'm guessing some kind of hash would work.

How about something like this? All you have to do is call the checkFile() method, specifying the first file to be checked, and call the method you already have for parsing files:

Code

checkFile($firstFile);

sub checkFile { my $fileToCheck = shift; # Get the name of the file to be checked my $nextFile = # Call method which 1) parses $fileToCheck for "jsp:include=filename.inc", and 2) returns the next "filename.inc" or undef checkFile($nextFile) if -e $nextFile; # Recursive call to check for next file... }