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

Some times things are so obvious that they are not documented. But who can tell?

I am looking for a file in a directory using the 'glob' <>. within that glob is a non-simple RE.

my @possible = <${pathHi}(.*[_-]?RTM[_-]).*[.]xlsx>; #perl glob
This throws no errors, but never returns anything either. I am looking for something like:
RTM.xlsx RTM-v3.3_.xlsx system_2_RTM_v3-4.xlsx system 3-RTM.xlsx #yes, embeded spaces in file names

As I searched, the only example was '*', and no description of what could be used, or what internals would be doing the processing.

Pointers to some docs?

It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Replies are listed 'Best First'.
Re: Using regex in file glob ?
by Lotus1 (Vicar) on May 03, 2021 at 13:50 UTC

    File::Glob gives you a list of the metacharacters. glob() doesn't do regular expressions. It uses wildcard characters in the metacharacter list similar to ls or dir from the command line.

Re: Using regex in file glob ?
by Fletch (Bishop) on May 03, 2021 at 17:36 UTC

    Perhaps Path::Tiny where the children method will take a regexp (sample from an OS X box):

    $ perl -MPath::Tiny=path -E 'say join( qq{\n}, path(q{/})->children(qr +/i[bn]|sr/) )' /usr /bin /sbin /Library /com.apple.TimeMachine.localsnapshots

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Using regex in file glob ?
by tybalt89 (Monsignor) on May 03, 2021 at 20:26 UTC

    A simple way...

    my @possible = grep /${pathHi}(.*[_-]?RTM[_-]).*[.]xlsx/, <*>;
Re: Using regex in file glob ?
by LanX (Saint) on May 03, 2021 at 13:52 UTC
    File-globs don't do regexes but wildcards like shell does.

    And I'm sure it's documented in glob

    If you want to apply regexes you need to work with opendir and check file by file, like inside a grep

    File::Find is also quite popular here.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    A reply falls below the community's threshold of quality. You may see it by logging in.