|
File::BSDGlob - Perl extension for BSD glob routine |
File::BSDGlob - Perl extension for BSD glob routine
use File::BSDGlob ':glob';
@list = glob('*.[ch]');
$homedir = glob('~gnat', GLOB_TILDE | GLOB_ERR);
if (GLOB_ERROR) {
# an error occurred reading $homedir
}
## override the core glob (even with -T)
use File::BSDGlob 'globally';
my @sources = <*.{c,h,y}>
File::BSDGlob implements the FreeBSD glob(3) routine, which is a superset
of the POSIX glob() (described in IEEE Std 1003.2 ``POSIX.2''). The
glob() routine takes a mandatory pattern argument, and an optional
flags argument, and returns a list of filenames matching the
pattern, with interpretation of the pattern modified by the flags
variable. The POSIX defined flags are:
GLOB_ERRglob() to return an error when it encounters a directory it
cannot open or read. Ordinarily glob() continues to find matches.
GLOB_MARKGLOB_NOCHECKglob() returns a list
consisting of only the pattern. If GLOB_QUOTE is set, its effect
is present in the pattern returned.
GLOB_NOSORTThe FreeBSD extensions to the POSIX standard are the following flags:
GLOB_BRACE{pat,pat,...} strings like csh(1).
The pattern '{}' is left unexpanded for historical reasons (and csh(1)
does the same thing to ease typing of find(1) patterns).
GLOB_NOMAGICGLOB_NOCHECK but it only returns the pattern if it does not
contain any of the special characters ``*'', ``?'' or ``[''. NOMAGIC is
provided to simplify implementing the historic csh(1) globbing
behaviour and should probably not be used anywhere else.
GLOB_QUOTEGLOB_TILDEGLOB_CSHGLOB_CSH is a synonym for
GLOB_BRACE | GLOB_NOMAGIC | GLOB_QUOTE | GLOB_TILDE.
The POSIX provided GLOB_APPEND, GLOB_DOOFFS, and the FreeBSD
extensions GLOB_ALTDIRFUNC, and GLOB_MAGCHAR flags have not been
implemented in the Perl version because they involve more complex
interaction with the underlying C structures.
glob() returns a list of matching paths, possibly zero length. If an
error occurred, &File::BSDGlob::GLOB_ERROR will be non-zero and $! will be
set. &File::BSDGlob::GLOB_ERROR is guaranteed to be zero if no error occurred,
or one of the following values otherwise:
GLOB_NOSPACEGLOB_ABENDIn the case where glob() has found some matching paths, but is
interrupted by an error, glob() will return a list of filenames and
set &File::BSDGlob::ERROR.
Note that glob() deviates from POSIX and FreeBSD glob(3) behaviour by
not considering ENOENT and ENOTDIR as errors - glob() will
continue processing despite those errors, unless the GLOB_ERR flag is
set.
Be aware that all filenames returned from File::BSDGlob are tainted.
glob "a* b*", you should
probably throw them in a set as in glob "{a*,b*}. This is because
the argument to glob isn't subjected to parsing by the C shell. Remember
that you can use a backslash to escape things.
The Perl interface was written by Nathan Torkington (gnat@frii.com), and is released under the artistic license. Further modifications were made by Greg Bacon <gbacon@cs.uah.edu>. The C glob code has the following copyright:
Copyright (c) 1989, 1993 The Regents of the University of California. All rights reserved. This code is derived from software contributed to Berkeley by Guido van Rossum.
For redistribution of the C glob code, read the copyright notice in the file bsd_glob.c, which is part of the File::BSDGlob source distribution.
|
File::BSDGlob - Perl extension for BSD glob routine |