tags:

views:

46

answers:

1

Perl question for you:

#!/usr/bin/perl
use File::Find;

#Find files
find(\&wanted, $dir);

sub wanted {    #Do something   }   
#Done going through all files, do below:

other stuff { }

So, I basically want to parse a directory and find certain kinds of files. I can do that successfully with File::Find. However, my next step is, once I'm done searching the files, I want to do my next process.

The problem is , whatever, I put after the sub wanted { #Do something } , gets executed, everytime, the file I want is not found! I know this is only logical for the program to do that. But, could you tell me what I'd need to do to accomplish this:

1] Find files : using > sub wanted { #Do something } 2] While no more files to search : >do something else { }

Thanks!

+1  A: 

UPDATED ANSWER: (after OP clarified that he simply wants to run some code after find() finishes searching):

Since find() is not searching in parallel, it will simply return when all of the search is completed. Therefore you don't need to do ANYTHING special to achieve your goal:

find(\&wanted, @directories_to_search);
# Here be code that runs after search completes.

ORIGINAL ANSWER

You can set founding of files flag in wanted subroutine:

my $files_not_found = 1;
find(\&wanted, @directories_to_search);
sub wanted { @args=@_; $files_not_found = 0; }
if ($files_not_found) { 
    print "No files found!\n";
}
# Here you do things after find is finished.
DVK
Well, there would be more than 1 file for a fact. Also, there might be anywhere between 1 and 50 files or maybe more. I want to run my next function only after ALL those 50 files have been parsed. I don't want to run it if (!$count_files) ... this would mean, that it would run 49 times!
c0d3rs
DVK
Thanks DVK, I didn't know it was not in parallel. I appreciate the quick reply!
c0d3rs