* On 2004:02:10:20:13:32-0600 I, Michael D Schleif <[EMAIL PROTECTED]>, scribed:
> * "Arms, Mike" <[EMAIL PROTECTED]> [2004:02:09:10:38:55-0700] scribed:
> <snip />
> 
> > Is there a Perl module that supports the "**" notation
> > in globbing where '**' matches zero or more levels of
> > directories?
> > 
> > Example:
> > 
> >   src/**/*.pl  would match any files or directories ending
> >                in the ".pl" suffix anywhere under the "src"
> >                directory
> > 
> > As illustration, the above pattern would match the following:
> > 
> >   src/app1/bobble.pl
> >   src/app1/foo.pl
> >   src/app1/testing/t1.pl
> >   src/app1/testing/t2.pl
> >   src/app2/any/number/of/subdirs/myFoo.pl
> >   src/test.pl
> <snip />
> 
> I have not read the whole spec; but, consider the following subroutine.
> Of course, you need to define $dir and $pat.
> 
>    sub parse_dir {
>       my $dir = shift;
>       opendir FH, $dir
>               or die "\n\tERROR: Cannot open \'$dir\' : $!\n\n";
>       for (readdir FH) {
>               next if /^\.+$/;
>               # Directory Test
>               parse_dir("$dir/$_")
>                       if -d "$dir/$_";
>               # File Test
>               next unless /$pat/;
>               print "$dir/$_\n"
>                       unless -d _;
>       }
>       closedir FH;
>       1;
>    }

And this is OS independent:

   #! perl

   use diagnostics;
   use strict;
   use warnings;

   my $sep = $^O =~ /win/i
           ? "\\"
           : "/";
   my $pat = "\.tmp$";
   my $dir = "\.";

   parse_dir($dir);

   exit 0;

   sub parse_dir {
           my $dir = shift;
           opendir FH, $dir
                   or die "\n\tERROR: Cannot open \'$dir\' : $!\n\n";
           for (readdir FH) {
                   next if /^\.+$/;
                   if (-d "$dir/$_") {
                           parse_dir(
                                   $dir
                                   . $sep
                                   . $_
                           );
                   } else {
                           next unless /$pat/;
                           print $dir
                                   . $sep
                                   . $_,"\n";
                   }
           }
           closedir FH;
           1;
   }


-- 
Best Regards,

mds
mds resource
877.596.8237
-
Dare to fix things before they break . . .
-
Our capacity for understanding is inversely proportional to how much
we think we know.  The more I know, the more I know I don't know . . .
--

Attachment: signature.asc
Description: Digital signature

Reply via email to