Advertisement

10.08.2008 at 06:27PM PDT, ID: 23799667 | Points: 250
[x]
Attachment Details

recursive function

Asked by mock5c in Perl Programming Language

Tags:

Attached is code that I'm trying to use to recursively go through directories and process files.  It works well if I start at a top level directory that contains subdirectories.  However, if I go into an individual directory (which does not have subdirectories) under the top level, it will not work.  This must be because the top level directory is always called "." instead of the full name so it fails under the directory pattern check.

Any elegant solution for this?  Also, can the find function search only directories or do I need to use the -d switch inside wanted()?  I was thinking it is someone inefficient that it is checking mostly files to see if they are directories.

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
use File::Find;
 
find(\&wanted, '.');
 
sub wanted {
  if(-d && /\d{7}/){
      opendir(DIR,"$File::Find::dir/$_");
      my @files = readdir(DIR);
      closedir(DIR);
      process_files(\@files,$upload_file_patterns{'patt'});
   }
}
[+][-]10.08.2008 at 06:56PM PDT, ID: 22675071

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.08.2008 at 07:18PM PDT, ID: 22675209

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.08.2008 at 07:54PM PDT, ID: 22675362

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.08.2008 at 08:12PM PDT, ID: 22675424

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.08.2008 at 08:26PM PDT, ID: 22675471

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.09.2008 at 01:04AM PDT, ID: 22676383

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.09.2008 at 05:28AM PDT, ID: 22677569

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628