jdporter has asked for the wisdom of the Perl Monks concerning the following question:

Anybody know of a good, powerful globbing module? I want something which can do recursive scanning. In addition to the standard glob patterns, it would accept things like:

Other features beyond the standard glob would be nice too.

Update: I need this to be platform independent, to the extent possible.

A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re: A better, more powerful fileglob?
by xdg (Monsignor) on Feb 15, 2007 at 19:11 UTC

    A quick CPAN search suggests perhaps File::Wildcard might suit you, though its syntax is a bit strange. Personally, I'd probably just use File::Find::Rule.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Thanks. I think I might go with File::Wildcard. Its syntax is a bit strange, but it's not entirely baroque.

      The problem with File::Find::Rule, for my purposes, is that I want to be able to specify the search rule entirely in one succinct string of text, such as a user might supply as a commandline argument. The power of File::Find::Rule is largely in its API, AFAICT.

      Update: I have integrated File::Wildcard into my program over here, and it works like a champ.

      A word spoken in Mind will reach its own level, in the objective world, by its own weight
        It shouldn't be terribly hard to implement that yourself using File::Find or File::Find::Rule, just a bit of parsing of the path string. Not much code and it will work exactly how you want.

                        - Ant
                        - Some of my best work - (1 2 3)

Re: A better, more powerful fileglob?
by Fletch (Bishop) on Feb 15, 2007 at 19:09 UTC

    Perhaps open a pipe to zsh and let it do the globular lifting?

    ## Off the cuff . . . sub zglob { my $glob = shift; open( my $z, qq{zsh -c 'print -N "$glob"' |} ) or die "can't open gl +obpipe: #!\n"; local( $/ ) = "\0"; my @ret; while( <$z> ) { chomp; push @ret, $_; } close( $z ); return @ret; }
Re: A better, more powerful fileglob?
by ikegami (Patriarch) on Feb 15, 2007 at 19:40 UTC
    I wonder if someone has written a module to apply XPath queries to a file system.
      One could of course read in the whole filesystem below the toplevel directory you intend to use, turn it into an XML-structure and then apply XPath rules to it.

      Something says me it will not be very efficient ...

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        Something says me it will not be very efficient ...

        The particular implementation you mentioned, serializing the file system tree into an XML doc then deserializing it into a XML tree, would indeed be inefficient.

        However, XPath can be applied to tree structures (such as a file system) in an efficient manner. It was designed to do just that.