bsd_glob#
Expand a shell-style pattern and return the list of matching paths.
Synopsis#
my @list = bsd_glob('*.[ch]');
my @homes = bsd_glob('~gnat', GLOB_TILDE | GLOB_ERR);
my @latest = bsd_glob('src/*.pl', GLOB_NOSORT);
What you get back#
A list of filenames, possibly empty. In scalar context you get the
count of matches. Filenames are returned as plain strings in the order
determined by the flags (alphabetical under the default GLOB_CSH,
unsorted under GLOB_NOSORT).
When the pattern matches nothing and neither GLOB_NOCHECK nor
GLOB_NOMAGIC is in effect, the list is empty. With GLOB_NOCHECK
the original pattern is returned as the sole element; with
GLOB_NOMAGIC the pattern is returned only when it contains no
metacharacters.
Examples#
use File::Glob ':bsd_glob';
my @perl = bsd_glob('*.pl'); # ('a.pl', 'b.pl', ...)
## Brace expansion — default flags include GLOB_BRACE
my @src = bsd_glob('{lib,t}/*.pm'); # files under lib/ and t/
## Tilde expansion to another user's home
my ($home) = bsd_glob('~gnat', GLOB_TILDE);
## Case-insensitive match
my @readmes = bsd_glob('readme*', GLOB_NOCASE);
Edge cases#
No second argument: flags come from
$File::Glob::DEFAULT_FLAGS(initialised toGLOB_CSH).GLOB_APPEND,GLOB_DOOFFS,GLOB_ALTDIRFUNC,GLOB_MAGCHARare masked out of the caller’s flags: they require C-level state pperl does not expose.A pattern containing an embedded NUL byte returns the empty list.
Missing pattern (zero-argument call) returns the empty list.
Differences from upstream#
bsd_glob_override(installed as the caller’sglobbyuse File::Glob ':bsd_glob') is an alias forbsd_globand does not implement the scalar-context iterator state machine upstream provides. In list context the behaviour matches; in scalar context upstream yields one name per call until exhausted, whereas pperl returns the match count. Covered byt/81-xs-native/File/Glob/*.t.Filenames are not tainted. pperl does not implement taint mode.
See also#
csh_glob— the form Perl’s built-inglobuses internally.GLOB_ERROR— non-zero after a traversal error.GLOB_CSH— the default flag bundle.GLOB_NOCHECK— return the pattern itself when nothing matches.