CINXE.COM
File::Glob - Perl extension for BSD glob routine - Perldoc Browser
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>File::Glob - Perl extension for BSD glob routine - Perldoc Browser</title> <link rel="search" href="/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser"> <link rel="canonical" href="https://perldoc.perl.org/File::Glob"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" /> <style> body { background: #f4f4f5; color: #020202; } .navbar-dark { background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%); background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%); background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%); filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0); background-repeat: repeat-x; } .navbar-dark .navbar-nav .nav-link, .navbar-dark .navbar-nav .nav-link:focus { color: #fff } .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 } #wrapperlicious { margin: 0 auto; font: 0.9em 'Helvetica Neue', Helvetica, sans-serif; font-weight: normal; line-height: 1.5em; margin: 0; padding: 0; } #wrapperlicious h1 { font-size: 1.5em } #wrapperlicious h2 { font-size: 1.3em } #wrapperlicious h3 { font-size: 1.1em } #wrapperlicious h4 { font-size: 0.9em } #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3, #wrapperlicious h4, #wrapperlicious dt { color: #020202; margin-top: 1em; margin-bottom: 1em; position: relative; font-weight: bold; } #wrapperlicious a { color: inherit; text-decoration: underline } #wrapperlicious #toc { text-decoration: none } #wrapperlicious a:hover { color: #2a2a2a } #wrapperlicious a img { border: 0 } #wrapperlicious :not(pre) > code { color: inherit; background-color: rgba(0, 0, 0, 0.04); border-radius: 3px; font: 0.9em Consolas, Menlo, Monaco, monospace; padding: 0.3em; } #wrapperlicious dd { margin: 0; margin-left: 2em; } #wrapperlicious dt { color: #2a2a2a; font-weight: bold; margin-left: 0.9em; } #wrapperlicious p { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious li > p { margin-bottom: 0; margin-top: 0; } #wrapperlicious pre { border: 1px solid #c1c1c1; border-radius: 3px; font: 100% Consolas, Menlo, Monaco, monospace; margin-bottom: 1em; margin-top: 1em; } #wrapperlicious pre > code { display: block; background-color: #f6f6f6; font: 0.9em Consolas, Menlo, Monaco, monospace; line-height: 1.5em; text-align: left; white-space: pre; padding: 1em; } #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul { margin-bottom: 1em; margin-top: 1em; } #wrapperlicious ul { list-style-type: square; } #wrapperlicious ul ul { margin-bottom: 0px; margin-top: 0px; } #footer { font-size: 0.8em; padding-top: 0.5em; text-align: center; } #more { display: inline; font-size: 0.8em; } #perldocdiv { background-color: #fff; border: 1px solid #c1c1c1; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; margin-left: auto; margin-right: auto; padding: 3em; padding-top: 1em; max-width: 960px; } #moduleversion { float: right } #wrapperlicious .leading-notice { font-style: italic; padding-left: 1em; margin-top: 1em; margin-bottom: 1em; } #wrapperlicious .permalink { display: none; left: -0.75em; position: absolute; padding-right: 0.25em; text-decoration: none; } #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink, #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink, #wrapperlicious dt:hover .permalink { display: block; } </style> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KVNWBNT5FB'); gtag('config', 'UA-50555-3'); </script> </head> <body> <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="/"><img src="/images/perl_camel_30.png" width="30" height="30" class="d-inline-block align-top" alt="Perl Camel Logo"> Perldoc Browser</a> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.22.0</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-stable"> <a class="dropdown-item" href="/File::Glob">Latest</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1/File::Glob">5.40.1</a> <a class="dropdown-item" href="/5.40.0/File::Glob">5.40.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3/File::Glob">5.38.3</a> <a class="dropdown-item" href="/5.38.2/File::Glob">5.38.2</a> <a class="dropdown-item" href="/5.38.1/File::Glob">5.38.1</a> <a class="dropdown-item" href="/5.38.0/File::Glob">5.38.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.36.3/File::Glob">5.36.3</a> <a class="dropdown-item" href="/5.36.2/File::Glob">5.36.2</a> <a class="dropdown-item" href="/5.36.1/File::Glob">5.36.1</a> <a class="dropdown-item" href="/5.36.0/File::Glob">5.36.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.34.3/File::Glob">5.34.3</a> <a class="dropdown-item" href="/5.34.2/File::Glob">5.34.2</a> <a class="dropdown-item" href="/5.34.1/File::Glob">5.34.1</a> <a class="dropdown-item" href="/5.34.0/File::Glob">5.34.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.32.1/File::Glob">5.32.1</a> <a class="dropdown-item" href="/5.32.0/File::Glob">5.32.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.30.3/File::Glob">5.30.3</a> <a class="dropdown-item" href="/5.30.2/File::Glob">5.30.2</a> <a class="dropdown-item" href="/5.30.1/File::Glob">5.30.1</a> <a class="dropdown-item" href="/5.30.0/File::Glob">5.30.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.28.3/File::Glob">5.28.3</a> <a class="dropdown-item" href="/5.28.2/File::Glob">5.28.2</a> <a class="dropdown-item" href="/5.28.1/File::Glob">5.28.1</a> <a class="dropdown-item" href="/5.28.0/File::Glob">5.28.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.26.3/File::Glob">5.26.3</a> <a class="dropdown-item" href="/5.26.2/File::Glob">5.26.2</a> <a class="dropdown-item" href="/5.26.1/File::Glob">5.26.1</a> <a class="dropdown-item" href="/5.26.0/File::Glob">5.26.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.24.4/File::Glob">5.24.4</a> <a class="dropdown-item" href="/5.24.3/File::Glob">5.24.3</a> <a class="dropdown-item" href="/5.24.2/File::Glob">5.24.2</a> <a class="dropdown-item" href="/5.24.1/File::Glob">5.24.1</a> <a class="dropdown-item" href="/5.24.0/File::Glob">5.24.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.4/File::Glob">5.22.4</a> <a class="dropdown-item" href="/5.22.3/File::Glob">5.22.3</a> <a class="dropdown-item" href="/5.22.2/File::Glob">5.22.2</a> <a class="dropdown-item" href="/5.22.1/File::Glob">5.22.1</a> <a class="dropdown-item active" href="/5.22.0/File::Glob">5.22.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.20.3/File::Glob">5.20.3</a> <a class="dropdown-item" href="/5.20.2/File::Glob">5.20.2</a> <a class="dropdown-item" href="/5.20.1/File::Glob">5.20.1</a> <a class="dropdown-item" href="/5.20.0/File::Glob">5.20.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.18.4/File::Glob">5.18.4</a> <a class="dropdown-item" href="/5.18.3/File::Glob">5.18.3</a> <a class="dropdown-item" href="/5.18.2/File::Glob">5.18.2</a> <a class="dropdown-item" href="/5.18.1/File::Glob">5.18.1</a> <a class="dropdown-item" href="/5.18.0/File::Glob">5.18.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.16.3/File::Glob">5.16.3</a> <a class="dropdown-item" href="/5.16.2/File::Glob">5.16.2</a> <a class="dropdown-item" href="/5.16.1/File::Glob">5.16.1</a> <a class="dropdown-item" href="/5.16.0/File::Glob">5.16.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.14.4/File::Glob">5.14.4</a> <a class="dropdown-item" href="/5.14.3/File::Glob">5.14.3</a> <a class="dropdown-item" href="/5.14.2/File::Glob">5.14.2</a> <a class="dropdown-item" href="/5.14.1/File::Glob">5.14.1</a> <a class="dropdown-item" href="/5.14.0/File::Glob">5.14.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.12.5/File::Glob">5.12.5</a> <a class="dropdown-item" href="/5.12.4/File::Glob">5.12.4</a> <a class="dropdown-item" href="/5.12.3/File::Glob">5.12.3</a> <a class="dropdown-item" href="/5.12.2/File::Glob">5.12.2</a> <a class="dropdown-item" href="/5.12.1/File::Glob">5.12.1</a> <a class="dropdown-item" href="/5.12.0/File::Glob">5.12.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.10.1/File::Glob">5.10.1</a> <a class="dropdown-item" href="/5.10.0/File::Glob">5.10.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.8.9/File::Glob">5.8.9</a> <a class="dropdown-item" href="/5.8.8/File::Glob">5.8.8</a> <a class="dropdown-item" href="/5.8.7/File::Glob">5.8.7</a> <a class="dropdown-item" href="/5.8.6/File::Glob">5.8.6</a> <a class="dropdown-item" href="/5.8.5/File::Glob">5.8.5</a> <a class="dropdown-item" href="/5.8.4/File::Glob">5.8.4</a> <a class="dropdown-item" href="/5.8.3/File::Glob">5.8.3</a> <a class="dropdown-item" href="/5.8.2/File::Glob">5.8.2</a> <a class="dropdown-item" href="/5.8.1/File::Glob">5.8.1</a> <a class="dropdown-item" href="/5.8.0/File::Glob">5.8.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.6.2/File::Glob">5.6.2</a> <a class="dropdown-item" href="/5.6.1/File::Glob">5.6.1</a> <a class="dropdown-item" href="/5.6.0/File::Glob">5.6.0</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.005_04/File::Glob">5.005_04</a> <a class="dropdown-item" href="/5.005_03/File::Glob">5.005_03</a> <a class="dropdown-item" href="/5.005_02/File::Glob">5.005_02</a> <a class="dropdown-item" href="/5.005_01/File::Glob">5.005_01</a> <a class="dropdown-item" href="/5.005/File::Glob">5.005</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-dev"> <a class="dropdown-item" href="/blead/File::Glob">blead</a> <a class="dropdown-item" href="/5.41.10/File::Glob">5.41.10</a> <a class="dropdown-item" href="/5.41.9/File::Glob">5.41.9</a> <a class="dropdown-item" href="/5.41.8/File::Glob">5.41.8</a> <a class="dropdown-item" href="/5.41.7/File::Glob">5.41.7</a> <a class="dropdown-item" href="/5.41.6/File::Glob">5.41.6</a> <a class="dropdown-item" href="/5.41.5/File::Glob">5.41.5</a> <a class="dropdown-item" href="/5.41.4/File::Glob">5.41.4</a> <a class="dropdown-item" href="/5.41.3/File::Glob">5.41.3</a> <a class="dropdown-item" href="/5.41.2/File::Glob">5.41.2</a> <a class="dropdown-item" href="/5.41.1/File::Glob">5.41.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.40.1-RC1/File::Glob">5.40.1-RC1</a> <a class="dropdown-item" href="/5.40.0-RC2/File::Glob">5.40.0-RC2</a> <a class="dropdown-item" href="/5.40.0-RC1/File::Glob">5.40.0-RC1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.39.10/File::Glob">5.39.10</a> <a class="dropdown-item" href="/5.39.9/File::Glob">5.39.9</a> <a class="dropdown-item" href="/5.39.8/File::Glob">5.39.8</a> <a class="dropdown-item" href="/5.39.7/File::Glob">5.39.7</a> <a class="dropdown-item" href="/5.39.6/File::Glob">5.39.6</a> <a class="dropdown-item" href="/5.39.5/File::Glob">5.39.5</a> <a class="dropdown-item" href="/5.39.4/File::Glob">5.39.4</a> <a class="dropdown-item" href="/5.39.3/File::Glob">5.39.3</a> <a class="dropdown-item" href="/5.39.2/File::Glob">5.39.2</a> <a class="dropdown-item" href="/5.39.1/File::Glob">5.39.1</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.38.3-RC1/File::Glob">5.38.3-RC1</a> </div> </li> <li class="nav-item dropdown text-nowrap"> <a class="nav-link dropdown-toggle" href="#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a> <div class="dropdown-menu" aria-labelledby="dropdownlink-nav"> <a class="dropdown-item" href="/5.22.0/perl">Perl</a> <a class="dropdown-item" href="/5.22.0/perlintro">Intro</a> <a class="dropdown-item" href="/5.22.0/perl#Tutorials">Tutorials</a> <a class="dropdown-item" href="/5.22.0/perlfaq">FAQs</a> <a class="dropdown-item" href="/5.22.0/perl#Reference-Manual">Reference</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.0/perlop">Operators</a> <a class="dropdown-item" href="/5.22.0/functions">Functions</a> <a class="dropdown-item" href="/5.22.0/variables">Variables</a> <a class="dropdown-item" href="/5.22.0/modules">Modules</a> <a class="dropdown-item" href="/5.22.0/perlutil">Utilities</a> <div class="dropdown-divider"></div> <a class="dropdown-item" href="/5.22.0/perldelta">Release Notes</a> <a class="dropdown-item" href="/5.22.0/perlcommunity">Community</a> <a class="dropdown-item" href="/5.22.0/perlhist">History</a> </div> </li> </ul> <ul class="navbar-nav"> <script> function set_expand (expand) { var perldocdiv = document.getElementById('perldocdiv'); var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width'); var expanded = (width == '' || width == 'none') ? true : false; if (expand === null) { expand = !expanded; } if ((expand && !expanded) || (!expand && expanded)) { perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px'); var button_classlist = document.getElementById('content-expand-button').classList; if (expand) { button_classlist.add('btn-light'); button_classlist.remove('btn-outline-light'); } else { button_classlist.add('btn-outline-light'); button_classlist.remove('btn-light'); } } return expand; } function toggle_expand () { var expand = set_expand(null); document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC'; } function read_expand () { return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function () { if (read_expand()) { set_expand(true); } }); } else if (read_expand()) { set_expand(true); } </script> <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-4" onclick="toggle_expand()">Expand</button> </ul> <form class="form-inline" method="get" action="/5.22.0/search"> <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search" value=""> </form> </div> </nav> <div id="wrapperlicious" class="container-fluid"> <div id="perldocdiv"> <div id="links"> <a href="/5.22.0/File::Glob">File::Glob</a> <div id="more"> (<a href="/5.22.0/File::Glob.txt">source</a>, <a href="https://metacpan.org/pod/File::Glob">CPAN</a>) </div> <div id="moduleversion">version 1.24</div> </div> <div class="leading-notice"> You are viewing the version of this documentation from Perl 5.22.0. <a href="/File::Glob">View the latest version</a> </div> <h1><a id="toc">CONTENTS</a></h1> <ul> <li> <a class="text-decoration-none" href="#NAME">NAME</a> </li> <li> <a class="text-decoration-none" href="#SYNOPSIS">SYNOPSIS</a> </li> <li> <a class="text-decoration-none" href="#DESCRIPTION">DESCRIPTION</a> <ul> <li> <a class="text-decoration-none" href="#META-CHARACTERS">META CHARACTERS</a> </li> <li> <a class="text-decoration-none" href="#EXPORTS">EXPORTS</a> <ul> <li> <a class="text-decoration-none" href="#:bsd_glob">:bsd_glob</a> </li> <li> <a class="text-decoration-none" href="#:glob">:glob</a> </li> <li> <a class="text-decoration-none" href="#bsd_glob">bsd_glob</a> </li> <li> <a class="text-decoration-none" href="#:nocase-and-:case">:nocase and :case</a> </li> <li> <a class="text-decoration-none" href="#csh_glob">csh_glob</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#POSIX-FLAGS">POSIX FLAGS</a> </li> </ul> </li> <li> <a class="text-decoration-none" href="#DIAGNOSTICS">DIAGNOSTICS</a> </li> <li> <a class="text-decoration-none" href="#NOTES">NOTES</a> </li> <li> <a class="text-decoration-none" href="#SEE-ALSO">SEE ALSO</a> </li> <li> <a class="text-decoration-none" href="#AUTHOR">AUTHOR</a> </li> </ul> <h1 id="NAME"><a class="permalink" href="#NAME">#</a>NAME</h1> <p>File::Glob - Perl extension for BSD glob routine</p> <h1 id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">#</a>SYNOPSIS</h1> <pre><code>use File::Glob ':bsd_glob'; @list = bsd_glob('*.[ch]'); $homedir = bsd_glob('~gnat', GLOB_TILDE | GLOB_ERR); if (GLOB_ERROR) { # an error occurred reading $homedir } ## override the core glob (CORE::glob() does this automatically ## by default anyway, since v5.6.0) use File::Glob ':globally'; my @sources = <*.{c,h,y}>; ## override the core glob, forcing case sensitivity use File::Glob qw(:globally :case); my @sources = <*.{c,h,y}>; ## override the core glob forcing case insensitivity use File::Glob qw(:globally :nocase); my @sources = <*.{c,h,y}>; ## glob on all files in home directory use File::Glob ':globally'; my @sources = <~gnat/*>;</code></pre> <h1 id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">#</a>DESCRIPTION</h1> <p>The glob angle-bracket operator <code><></code> is a pathname generator that implements the rules for file name pattern matching used by Unix-like shells such as the Bourne shell or C shell.</p> <p>File::Glob::bsd_glob() implements the FreeBSD glob(3) routine, which is a superset of the POSIX glob() (described in IEEE Std 1003.2 "POSIX.2"). bsd_glob() takes a mandatory <code>pattern</code> argument, and an optional <code>flags</code> argument, and returns a list of filenames matching the pattern, with interpretation of the pattern modified by the <code>flags</code> variable.</p> <p>Since v5.6.0, Perl's CORE::glob() is implemented in terms of bsd_glob(). Note that they don't share the same prototype--CORE::glob() only accepts a single argument. Due to historical reasons, CORE::glob() will also split its argument on whitespace, treating it as multiple patterns, whereas bsd_glob() considers them as one pattern. But see <code>:bsd_glob</code> under <a href="#EXPORTS">"EXPORTS"</a>, below.</p> <h2 id="META-CHARACTERS"><a class="permalink" href="#META-CHARACTERS">#</a><a id="META"></a>META CHARACTERS</h2> <pre><code class="plaintext">\ Quote the next metacharacter [] Character class {} Multiple pattern * Match any string of characters ? Match any single character ~ User name home directory</code></pre> <p>The metanotation <code>a{b,c,d}e</code> is a shorthand for <code>abe ace ade</code>. Left to right order is preserved, with results of matches being sorted separately at a low level to preserve this order. As a special case <code>{</code>, <code>}</code>, and <code>{}</code> are passed undisturbed.</p> <h2 id="EXPORTS"><a class="permalink" href="#EXPORTS">#</a>EXPORTS</h2> <p>See also the <a href="#POSIX-FLAGS">"POSIX FLAGS"</a> below, which can be exported individually.</p> <h3 id=":bsd_glob"><a class="permalink" href="#:bsd_glob">#</a><a id="bsd_glob1"></a><code>:bsd_glob</code></h3> <p>The <code>:bsd_glob</code> export tag exports bsd_glob() and the constants listed below. It also overrides glob() in the calling package with one that behaves like bsd_glob() with regard to spaces (the space is treated as part of a file name), but supports iteration in scalar context; i.e., it preserves the core function's feature of returning the next item each time it is called.</p> <h3 id=":glob"><a class="permalink" href="#:glob">#</a><a id="glob"></a><code>:glob</code></h3> <p>The <code>:glob</code> tag, now discouraged, is the old version of <code>:bsd_glob</code>. It exports the same constants and functions, but its glob() override does not support iteration; it returns the last file name in scalar context. That means this will loop forever:</p> <pre><code> use File::Glob ':glob'; while (my $file = <* copy.txt>) { ... }</code></pre> <h3 id="bsd_glob"><a class="permalink" href="#bsd_glob">#</a><code>bsd_glob</code></h3> <p>This function, which is included in the two export tags listed above, takes one or two arguments. The first is the glob pattern. The second is a set of flags ORed together. The available flags are listed below under <a href="#POSIX-FLAGS">"POSIX FLAGS"</a>. If the second argument is omitted, <code>GLOB_CSH</code> (or <code>GLOB_CSH|GLOB_NOCASE</code> on VMS and DOSish systems) is used by default.</p> <h3 id=":nocase-and-:case"><a class="permalink" href="#:nocase-and-:case">#</a><a id="nocase-and-:case"></a><code>:nocase</code> and <code>:case</code></h3> <p>These two export tags globally modify the default flags that bsd_glob() and, except on VMS, Perl's built-in <code>glob</code> operator use. <code>GLOB_NOCASE</code> is turned on or off, respectively.</p> <h3 id="csh_glob"><a class="permalink" href="#csh_glob">#</a><code>csh_glob</code></h3> <p>The csh_glob() function can also be exported, but you should not use it directly unless you really know what you are doing. It splits the pattern into words and feeds each one to bsd_glob(). Perl's own glob() function uses this internally.</p> <h2 id="POSIX-FLAGS"><a class="permalink" href="#POSIX-FLAGS">#</a><a id="POSIX"></a>POSIX FLAGS</h2> <p>The POSIX defined flags for bsd_glob() are:</p> <dl> <dt id="GLOB_ERR"><a class="permalink" href="#GLOB_ERR">#</a><code>GLOB_ERR</code></dt> <dd> <p>Force bsd_glob() to return an error when it encounters a directory it cannot open or read. Ordinarily bsd_glob() continues to find matches.</p> </dd> <dt id="GLOB_LIMIT"><a class="permalink" href="#GLOB_LIMIT">#</a><code>GLOB_LIMIT</code></dt> <dd> <p>Make bsd_glob() return an error (GLOB_NOSPACE) when the pattern expands to a size bigger than the system constant <code>ARG_MAX</code> (usually found in limits.h). If your system does not define this constant, bsd_glob() uses <code>sysconf(_SC_ARG_MAX)</code> or <code>_POSIX_ARG_MAX</code> where available (in that order). You can inspect these values using the standard <code>POSIX</code> extension.</p> </dd> <dt id="GLOB_MARK"><a class="permalink" href="#GLOB_MARK">#</a><code>GLOB_MARK</code></dt> <dd> <p>Each pathname that is a directory that matches the pattern has a slash appended.</p> </dd> <dt id="GLOB_NOCASE"><a class="permalink" href="#GLOB_NOCASE">#</a><code>GLOB_NOCASE</code></dt> <dd> <p>By default, file names are assumed to be case sensitive; this flag makes bsd_glob() treat case differences as not significant.</p> </dd> <dt id="GLOB_NOCHECK"><a class="permalink" href="#GLOB_NOCHECK">#</a><code>GLOB_NOCHECK</code></dt> <dd> <p>If the pattern does not match any pathname, then bsd_glob() returns a list consisting of only the pattern. If <code>GLOB_QUOTE</code> is set, its effect is present in the pattern returned.</p> </dd> <dt id="GLOB_NOSORT"><a class="permalink" href="#GLOB_NOSORT">#</a><code>GLOB_NOSORT</code></dt> <dd> <p>By default, the pathnames are sorted in ascending ASCII order; this flag prevents that sorting (speeding up bsd_glob()).</p> </dd> </dl> <p>The FreeBSD extensions to the POSIX standard are the following flags:</p> <dl> <dt id="GLOB_BRACE"><a class="permalink" href="#GLOB_BRACE">#</a><code>GLOB_BRACE</code></dt> <dd> <p>Pre-process the string to expand <code>{pat,pat,...}</code> 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).</p> </dd> <dt id="GLOB_NOMAGIC"><a class="permalink" href="#GLOB_NOMAGIC">#</a><code>GLOB_NOMAGIC</code></dt> <dd> <p>Same as <code>GLOB_NOCHECK</code> but it only returns the pattern if it does not contain any of the special characters "*", "?" or "[". <code>NOMAGIC</code> is provided to simplify implementing the historic csh(1) globbing behaviour and should probably not be used anywhere else.</p> </dd> <dt id="GLOB_QUOTE"><a class="permalink" href="#GLOB_QUOTE">#</a><code>GLOB_QUOTE</code></dt> <dd> <p>Use the backslash ('\') character for quoting: every occurrence of a backslash followed by a character in the pattern is replaced by that character, avoiding any special interpretation of the character. (But see below for exceptions on DOSISH systems).</p> </dd> <dt id="GLOB_TILDE"><a class="permalink" href="#GLOB_TILDE">#</a><code>GLOB_TILDE</code></dt> <dd> <p>Expand patterns that start with '~' to user name home directories.</p> </dd> <dt id="GLOB_CSH"><a class="permalink" href="#GLOB_CSH">#</a><code>GLOB_CSH</code></dt> <dd> <p>For convenience, <code>GLOB_CSH</code> is a synonym for <code>GLOB_BRACE | GLOB_NOMAGIC | GLOB_QUOTE | GLOB_TILDE | GLOB_ALPHASORT</code>.</p> </dd> </dl> <p>The POSIX provided <code>GLOB_APPEND</code>, <code>GLOB_DOOFFS</code>, and the FreeBSD extensions <code>GLOB_ALTDIRFUNC</code>, and <code>GLOB_MAGCHAR</code> flags have not been implemented in the Perl version because they involve more complex interaction with the underlying C structures.</p> <p>The following flag has been added in the Perl implementation for csh compatibility:</p> <dl> <dt id="GLOB_ALPHASORT"><a class="permalink" href="#GLOB_ALPHASORT">#</a><code>GLOB_ALPHASORT</code></dt> <dd> <p>If <code>GLOB_NOSORT</code> is not in effect, sort filenames is alphabetical order (case does not matter) rather than in ASCII order.</p> </dd> </dl> <h1 id="DIAGNOSTICS"><a class="permalink" href="#DIAGNOSTICS">#</a>DIAGNOSTICS</h1> <p>bsd_glob() returns a list of matching paths, possibly zero length. If an error occurred, &File::Glob::GLOB_ERROR will be non-zero and <code>$!</code> will be set. &File::Glob::GLOB_ERROR is guaranteed to be zero if no error occurred, or one of the following values otherwise:</p> <dl> <dt id="GLOB_NOSPACE"><a class="permalink" href="#GLOB_NOSPACE">#</a><code>GLOB_NOSPACE</code></dt> <dd> <p>An attempt to allocate memory failed.</p> </dd> <dt id="GLOB_ABEND"><a class="permalink" href="#GLOB_ABEND">#</a><code>GLOB_ABEND</code></dt> <dd> <p>The glob was stopped because an error was encountered.</p> </dd> </dl> <p>In the case where bsd_glob() has found some matching paths, but is interrupted by an error, it will return a list of filenames <b>and</b> set &File::Glob::ERROR.</p> <p>Note that bsd_glob() deviates from POSIX and FreeBSD glob(3) behaviour by not considering <code>ENOENT</code> and <code>ENOTDIR</code> as errors - bsd_glob() will continue processing despite those errors, unless the <code>GLOB_ERR</code> flag is set.</p> <p>Be aware that all filenames returned from File::Glob are tainted.</p> <h1 id="NOTES"><a class="permalink" href="#NOTES">#</a>NOTES</h1> <ul> <li><p>If you want to use multiple patterns, e.g. <code>bsd_glob("a* b*")</code>, you should probably throw them in a set as in <code>bsd_glob("{a*,b*}")</code>. This is because the argument to bsd_glob() isn't subjected to parsing by the C shell. Remember that you can use a backslash to escape things.</p> </li> <li><p>On DOSISH systems, backslash is a valid directory separator character. In this case, use of backslash as a quoting character (via GLOB_QUOTE) interferes with the use of backslash as a directory separator. The best (simplest, most portable) solution is to use forward slashes for directory separators, and backslashes for quoting. However, this does not match "normal practice" on these systems. As a concession to user expectation, therefore, backslashes (under GLOB_QUOTE) only quote the glob metacharacters '[', ']', '{', '}', '-', '~', and backslash itself. All other backslashes are passed through unchanged.</p> </li> <li><p>Win32 users should use the real slash. If you really want to use backslashes, consider using Sarathy's File::DosGlob, which comes with the standard Perl distribution.</p> </li> </ul> <h1 id="SEE-ALSO"><a class="permalink" href="#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1> <p><a href="/5.22.0/perlfunc#glob">"glob" in perlfunc</a>, glob(3)</p> <h1 id="AUTHOR"><a class="permalink" href="#AUTHOR">#</a>AUTHOR</h1> <p>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>, Gurusamy Sarathy <gsar@activestate.com>, and Thomas Wegner <wegner_thomas@yahoo.com>. The C glob code has the following copyright:</p> <pre><code class="plaintext">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. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the University nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</code></pre> </div> <div id="footer"> <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p> <p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p> </div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script> <script src="/js/highlight.pack.js"></script> <script>hljs.highlightAll();</script> </body> </html>