oly
oly

Reputation: 33

File::Globstar not working for some patterns

I am trying to use the File::Globstar module to search for files recursively. https://metacpan.org/pod/File::Globstar#EXAMPLES.

However, some of the patterns given in the documentation are not working for me when the path contains a . or a _.

For example, the search is empty when I do either of the following:

use File::Globstar qw(globstar);
my $path = 'D:/a.a/b/c/**/*.js';
my @results = globstar $path;

or

use File::Globstar qw(globstar);
my $path = 'D:/a_a/b/c/**/*.js';
my @results = globstar $path;

However, these work when I avoid using **.

my @results = globstar 'D:/a.a/b/c/e/*.js' 

Am I doing something wrong?

Upvotes: 1

Views: 390

Answers (1)

ikegami
ikegami

Reputation: 385764

This appears to be a bug in File::Globstar.

[ Fixed in 0.6 ]

>md f_oo & md f_oo\bar & copy nul f_oo\bar\a.js >nul

>perl -MFile::Globstar=globstar -e"CORE::say for globstar 'f_oo/**/*.js'"

>md f.oo & md f.oo\bar & copy nul f.oo\bar\a.js >nul

>perl -MFile::Globstar=globstar -e"CORE::say for globstar 'f.oo/**/*.js'"

>md foo & md foo\bar & copy nul foo\bar\a.js >nul

>perl -MFile::Globstar=globstar -e"CORE::say for globstar 'foo/**/*.js'"
foo/bar/a.js

The bug isn't Windows-specific.

$ md -p f_oo/bar; touch f_oo/bar/a.js

$ perl -MFile::Globstar=globstar -e'CORE::say for globstar "f_oo/**/*.js"'

$ md -p f.oo/bar; touch f.oo/bar/a.js

$ perl -MFile::Globstar=globstar -e'CORE::say for globstar "f.oo/**/*.js"'

$ md -p foo/bar; touch foo/bar/a.js

$ perl -MFile::Globstar=globstar -e'CORE::say for globstar "foo/**/*.js"'
foo/bar/a.js

Attempts to escape the problematic characters proved fruitless on both systems.

You should reach out to the maintainer.


You could possibly use File::Find::Rule instead of File::Globstar.

>md f_o.o & md f_o.o\bar & copy nul f_o.o\bar\a.js >nul

>perl -MFile::Find::Rule -e"CORE::say for File::Find::Rule->name('*.js')->in('f_o.o')"
f_o.o/bar/a.js

Upvotes: 2

Related Questions