{
    "mode": "perldoc",
    "parameter": "File::Glob",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/File%3A%3AGlob/json",
    "generated": "2026-05-30T06:07:24Z",
    "synopsis": "use File::Glob ':bsdglob';\n@list = bsdglob('*.[ch]');\n$homedir = bsdglob('~gnat', GLOBTILDE | GLOBERR);\nif (GLOBERROR) {\n# an error occurred reading $homedir\n}\n## override the core glob (CORE::glob() does this automatically\n## by default anyway, since v5.6.0)\nuse File::Glob ':globally';\nmy @sources = <*.{c,h,y}>;\n## override the core glob, forcing case sensitivity\nuse File::Glob qw(:globally :case);\nmy @sources = <*.{c,h,y}>;\n## override the core glob forcing case insensitivity\nuse File::Glob qw(:globally :nocase);\nmy @sources = <*.{c,h,y}>;\n## glob on all files in home directory\nuse File::Glob ':globally';\nmy @sources = <~gnat/*>;",
    "sections": {
        "NAME": {
            "content": "File::Glob - Perl extension for BSD glob routine\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use File::Glob ':bsdglob';\n\n@list = bsdglob('*.[ch]');\n$homedir = bsdglob('~gnat', GLOBTILDE | GLOBERR);\n\nif (GLOBERROR) {\n# an error occurred reading $homedir\n}\n\n## override the core glob (CORE::glob() does this automatically\n## by default anyway, since v5.6.0)\nuse File::Glob ':globally';\nmy @sources = <*.{c,h,y}>;\n\n## override the core glob, forcing case sensitivity\nuse File::Glob qw(:globally :case);\nmy @sources = <*.{c,h,y}>;\n\n## override the core glob forcing case insensitivity\nuse File::Glob qw(:globally :nocase);\nmy @sources = <*.{c,h,y}>;\n\n## glob on all files in home directory\nuse File::Glob ':globally';\nmy @sources = <~gnat/*>;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The glob angle-bracket operator \"<>\" is a pathname generator that\nimplements the rules for file name pattern matching used by Unix-like\nshells such as the Bourne shell or C shell.\n\nFile::Glob::bsdglob() implements the FreeBSD glob(3) routine, which is\na superset of the POSIX glob() (described in IEEE Std 1003.2 \"POSIX.2\").\nbsdglob() takes a mandatory \"pattern\" argument, and an optional \"flags\"\nargument, and returns a list of filenames matching the pattern, with\ninterpretation of the pattern modified by the \"flags\" variable.\n\nSince v5.6.0, Perl's CORE::glob() is implemented in terms of bsdglob().\nNote that they don't share the same prototype--CORE::glob() only accepts\na single argument. Due to historical reasons, CORE::glob() will also\nsplit its argument on whitespace, treating it as multiple patterns,\nwhereas bsdglob() considers them as one pattern. But see \":bsdglob\"\nunder \"EXPORTS\", below.\n\nMETA CHARACTERS\n\\       Quote the next metacharacter\n[]      Character class\n{}      Multiple pattern\n*       Match any string of characters\n?       Match any single character\n~       User name home directory\n\nThe metanotation \"a{b,c,d}e\" is a shorthand for \"abe ace ade\". Left to\nright order is preserved, with results of matches being sorted\nseparately at a low level to preserve this order. As a special case \"{\",\n\"}\", and \"{}\" are passed undisturbed.\n\nEXPORTS\nSee also the \"POSIX FLAGS\" below, which can be exported individually.\n\n\":bsdglob\"\nThe \":bsdglob\" export tag exports bsdglob() and the constants listed\nbelow. It also overrides glob() in the calling package with one that\nbehaves like bsdglob() with regard to spaces (the space is treated as\npart of a file name), but supports iteration in scalar context; i.e., it\npreserves the core function's feature of returning the next item each\ntime it is called.\n\n\":glob\"\nThe \":glob\" tag, now discouraged, is the old version of \":bsdglob\". It\nexports the same constants and functions, but its glob() override does\nnot support iteration; it returns the last file name in scalar context.\nThat means this will loop forever:\n\nuse File::Glob ':glob';\nwhile (my $file = <* copy.txt>) {\n...\n}\n\n\"bsdglob\"\nThis function, which is included in the two export tags listed above,\ntakes one or two arguments. The first is the glob pattern. The second,\nif given, is a set of flags ORed together. The available flags and the\ndefault set of flags are listed below under \"POSIX FLAGS\".\n\nRemember that to use the named constants for flags you must import them,\nfor example with \":bsdglob\" described above. If not imported, and \"use\nstrict\" is not in effect, then the constants will be treated as bareword\nstrings, which won't do what you what.\n\n\":nocase\" and \":case\"\nThese two export tags globally modify the default flags that bsdglob()\nand, except on VMS, Perl's built-in \"glob\" operator use. \"GLOBNOCASE\"\nis turned on or off, respectively.\n\n\"cshglob\"\nThe cshglob() function can also be exported, but you should not use it\ndirectly unless you really know what you are doing. It splits the\npattern into words and feeds each one to bsdglob(). Perl's own glob()\nfunction uses this internally.\n\nPOSIX FLAGS\nIf no flags argument is give then \"GLOBCSH\" is set, and on VMS and\nWindows systems, \"GLOBNOCASE\" too. Otherwise the flags to use are\ndetermined solely by the flags argument. The POSIX defined flags are:\n\n\"GLOBERR\"\nForce bsdglob() to return an error when it encounters a directory\nit cannot open or read. Ordinarily bsdglob() continues to find\nmatches.\n\n\"GLOBLIMIT\"\nMake bsdglob() return an error (GLOBNOSPACE) when the pattern\nexpands to a size bigger than the system constant \"ARGMAX\" (usually\nfound in limits.h). If your system does not define this constant,\nbsdglob() uses \"sysconf(SCARGMAX)\" or \"POSIXARGMAX\" where\navailable (in that order). You can inspect these values using the\nstandard \"POSIX\" extension.\n\n\"GLOBMARK\"\nEach pathname that is a directory that matches the pattern has a\nslash appended.\n\n\"GLOBNOCASE\"\nBy default, file names are assumed to be case sensitive; this flag\nmakes bsdglob() treat case differences as not significant.\n\n\"GLOBNOCHECK\"\nIf the pattern does not match any pathname, then bsdglob() returns\na list consisting of only the pattern. If \"GLOBQUOTE\" is set, its\neffect is present in the pattern returned.\n\n\"GLOBNOSORT\"\nBy default, the pathnames are sorted in ascending ASCII order; this\nflag prevents that sorting (speeding up bsdglob()).\n\nThe FreeBSD extensions to the POSIX standard are the following flags:\n\n\"GLOBBRACE\"\nPre-process the string to expand \"{pat,pat,...}\" strings like\ncsh(1). The pattern '{}' is left unexpanded for historical reasons\n(and csh(1) does the same thing to ease typing of find(1) patterns).\n\n\"GLOBNOMAGIC\"\nSame as \"GLOBNOCHECK\" but it only returns the pattern if it does\nnot contain any of the special characters \"*\", \"?\" or \"[\". \"NOMAGIC\"\nis provided to simplify implementing the historic csh(1) globbing\nbehaviour and should probably not be used anywhere else.\n\n\"GLOBQUOTE\"\nUse the backslash ('\\') character for quoting: every occurrence of a\nbackslash followed by a character in the pattern is replaced by that\ncharacter, avoiding any special interpretation of the character.\n(But see below for exceptions on DOSISH systems).\n\n\"GLOBTILDE\"\nExpand patterns that start with '~' to user name home directories.\n\n\"GLOBCSH\"\nFor convenience, \"GLOBCSH\" is a synonym for \"GLOBBRACE |\nGLOBNOMAGIC | GLOBQUOTE | GLOBTILDE | GLOBALPHASORT\".\n\nThe POSIX provided \"GLOBAPPEND\", \"GLOBDOOFFS\", and the FreeBSD\nextensions \"GLOBALTDIRFUNC\", and \"GLOBMAGCHAR\" flags have not been\nimplemented in the Perl version because they involve more complex\ninteraction with the underlying C structures.\n\nThe following flag has been added in the Perl implementation for csh\ncompatibility:\n\n\"GLOBALPHASORT\"\nIf \"GLOBNOSORT\" is not in effect, sort filenames is alphabetical\norder (case does not matter) rather than in ASCII order.\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "bsdglob() returns a list of matching paths, possibly zero length. If an\nerror occurred, &File::Glob::GLOBERROR will be non-zero and $! will be\nset. &File::Glob::GLOBERROR is guaranteed to be zero if no error\noccurred, or one of the following values otherwise:\n\n\"GLOBNOSPACE\"\nAn attempt to allocate memory failed.\n\n\"GLOBABEND\"\nThe glob was stopped because an error was encountered.\n\nIn the case where bsdglob() has found some matching paths, but is\ninterrupted by an error, it will return a list of filenames and set\n&File::Glob::ERROR.\n\nNote that bsdglob() deviates from POSIX and FreeBSD glob(3) behaviour\nby not considering \"ENOENT\" and \"ENOTDIR\" as errors - bsdglob() will\ncontinue processing despite those errors, unless the \"GLOBERR\" flag is\nset.\n\nBe aware that all filenames returned from File::Glob are tainted.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "*   If you want to use multiple patterns, e.g. \"bsdglob(\"a* b*\")\", you\nshould probably throw them in a set as in \"bsdglob(\"{a*,b*}\")\".\nThis is because the argument to bsdglob() isn't subjected to\nparsing by the C shell. Remember that you can use a backslash to\nescape things.\n\n*   On DOSISH systems, backslash is a valid directory separator\ncharacter. In this case, use of backslash as a quoting character\n(via GLOBQUOTE) interferes with the use of backslash as a directory\nseparator. The best (simplest, most portable) solution is to use\nforward slashes for directory separators, and backslashes for\nquoting. However, this does not match \"normal practice\" on these\nsystems. As a concession to user expectation, therefore, backslashes\n(under GLOBQUOTE) only quote the glob metacharacters '[', ']', '{',\n'}', '-', '~', and backslash itself. All other backslashes are\npassed through unchanged.\n\n*   Win32 users should use the real slash. If you really want to use\nbackslashes, consider using Sarathy's File::DosGlob, which comes\nwith the standard Perl distribution.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "\"glob\" in perlfunc, glob(3)\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "The Perl interface was written by Nathan Torkington <gnat@frii.com>, and\nis released under the artistic license. Further modifications were made\nby Greg Bacon <gbacon@cs.uah.edu>, Gurusamy Sarathy\n<gsar@activestate.com>, and Thomas Wegner <wegnerthomas@yahoo.com>. The\nC glob code has the following copyright:\n\nCopyright (c) 1989, 1993 The Regents of the University of California.\nAll rights reserved.\n\nThis code is derived from software contributed to Berkeley by Guido van\nRossum.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n1.  Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n\n2.  Redistributions in binary form must reproduce the above copyright\nnotice, this list of conditions and the following disclaimer in the\ndocumentation and/or other materials provided with the distribution.\n\n3.  Neither the name of the University nor the names of its contributors\nmay be used to endorse or promote products derived from this\nsoftware without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS \"AS IS\" AND\nANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE\nLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\nCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\nSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\nINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\nCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\nARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\nTHE POSSIBILITY OF SUCH DAMAGE.\n",
            "subsections": []
        }
    },
    "summary": "File::Glob - Perl extension for BSD glob routine",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "glob",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/glob/3/json"
        }
    ]
}