File::Glob#
POSIX pathname globbing - expand shell-style wildcard patterns into lists of filenames.
File::Glob is what backs Perl’s built-in glob operator and its angle-bracket form <*.pl>. Give it a pattern with shell metacharacters (*, ?, [...], {a,b,c}, ~user) and you get back the list of paths on disk that match. The same machinery is exposed directly as bsd_glob when you want explicit control over flags.
The mental model is simple: a pattern goes in, a list of real filenames comes out. Behaviour is tuned by a bitmask of GLOB_* flags - tilde expansion, brace expansion, case folding, sort order, and what happens when nothing matches are all flag-controlled. Every flag has a named constant (GLOB_TILDE, GLOB_BRACE, GLOB_NOCASE, GLOB_NOMAGIC, GLOB_CSH, etc.) and they OR together.
Three call styles, one engine: the built-in glob, the angle-bracket form <*.pl> and bsd_glob all run the same matcher, so they agree on flag handling, on sort order and on what $File::Glob::DEFAULT_FLAGS means. None of them forks a shell.
use File::Glob ':bsd_glob';
my @pl = <*.pl>; # angle-bracket form
my @c = bsd_glob('*.[ch]'); # function form, default flags
my @hd = bsd_glob('~gnat', GLOB_TILDE | GLOB_ERR);
The default flag set is GLOB_CSH - brace expansion, tilde expansion, backslash quoting, alphabetical sort, and the GLOB_NOMAGIC fallback that returns the literal pattern when it has no metacharacters and doesn’t match. Two import tags nudge the default: :nocase turns GLOB_NOCASE on globally, :case turns it off.
This is a native implementation of the XS half of File::Glob 1.44, the BSD glob engine included; File/Glob.pm is used unchanged. use File::Glob ':glob' exports bsd_glob, GLOB_ERROR and the constants; ':bsd_glob' exports the same and also replaces the caller’s glob with one that takes its pattern whole instead of splitting it on whitespace; ':globally' makes csh_glob the glob of every package.
Differences from upstream#
None.
Functions#
Globbing#
bsd_glob_override#
The glob that use File::Glob ':bsd_glob' installs in the calling package, replacing the built-in.
bsd_glob#
Expand a shell-style pattern and return the list of matching paths.
csh_glob#
Expand a pattern using the default flag set - the engine behind Perl’s built-in glob.
GLOB_ERROR#
Report the error status of the most recent bsd_glob call.