CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
recursivly matching string (a filename) in file, then testing said filename for same string, etc, etc...

 



fhare
New User

Jul 21, 2008, 1:49 PM

Post #1 of 2 (2752 views)
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.


stenrap
Novice

Jul 24, 2008, 12:04 AM

Post #2 of 2 (2718 views)
Re: [fhare] recursivly matching string (a filename) in file, then testing said filename for same string, etc, etc... [In reply to] Can't Post

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...
}



(This post was edited by stenrap on Jul 24, 2008, 12:06 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives