Hi Monks,
I am an old dog trying to learn some PERL tricks. I am getting back into PERL after more than a decade away. I am attempting to use File::Find to search for multiple patters and return the results as an array.
I have read the Beginners Guide and combed this site but I must be missing something simple?
Here's what I have so far
The output is as follows:use strict; use warnings; use Posix; use File::Find; sub findfile { my @Result = (); my $Start = $_[0]; print "Start: [$Start]\n"; if (scalar(@_) >= 2) { foreach my $x (1 .. scalar(@_) - 1) { find( sub { my @finds = grep { $_ =~ /$_[$x]/ } ($File::Fi +nd::name); if (scalar(@finds) > 0) { my $find=$finds[0]; if ($find eq $File::Find::name) { push @Result, $File::Find::name; return; } } }, $Start ); } return @Result; } } my @Paths = findfile("C:/Program Files (x86)/Nimsoft/bin", "*.exe", "* +.txt"); foreach ( @Paths ) { print "$_\n"; }
C:/Program Files (x86)/Nimsoft/bin C:/Program Files (x86)/Nimsoft/bin/nimalarm.exe C:/Program Files (x86)/Nimsoft/bin/nimboss.exe C:/Program Files (x86)/Nimsoft/bin/nimbus.exe C:/Program Files (x86)/Nimsoft/bin/nimqos.exe C:/Program Files (x86)/Nimsoft/bin/nimqosdefinition.exe C:/Program Files (x86)/Nimsoft/bin/pu.exe C:/Program Files (x86)/Nimsoft/bin C:/Program Files (x86)/Nimsoft/bin/nimalarm.exe C:/Program Files (x86)/Nimsoft/bin/nimboss.exe C:/Program Files (x86)/Nimsoft/bin/nimbus.exe C:/Program Files (x86)/Nimsoft/bin/nimqos.exe C:/Program Files (x86)/Nimsoft/bin/nimqosdefinition.exe C:/Program Files (x86)/Nimsoft/bin/pu.exe
I am going cross-eyed trying to figure this out. Why am I getting the list of exe files twice? Also, I don't get why the directory itself is printing out?
Any assistance would be very much appreciated
I also know I am showing Windows here. But, if possib;e the routine would be able to run on Linux/Unix as well.
In reply to Finding files with multiple patterns by pgduke65
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |