GLOB_ERROR#

Report the error status of the most recent bsd_glob call.

Synopsis#

my @files = bsd_glob('~nobody', GLOB_TILDE | GLOB_ERR);
if (GLOB_ERROR) {
    warn "glob failed: $!";
}

What you get back#

An integer. Zero means the last bsd_glob call completed without error. A non-zero value signals that an error interrupted traversal: GLOB_NOSPACE for allocation failure, GLOB_ABEND for a stopped traversal. When non-zero, $! carries the underlying errno.

Examples#

use File::Glob ':bsd_glob';
my @out = bsd_glob('/root/*', GLOB_ERR);   # root-only dir
print "error\n" if GLOB_ERROR;             # usually prints under non-root

Edge cases#

  • Reading GLOB_ERROR without a preceding glob returns 0.

  • It is 0 after a glob that completed, with or without matches.

  • An unreadable directory stops a glob made with GLOB_ERR (GLOB_ABEND, -2); without GLOB_ERR one that cannot be read for want of permission, or that does not exist, is skipped.

  • The built-in glob and <*.c> set it too.

See also#

  • bsd_glob - the call whose outcome this function reports.

  • GLOB_ERR - the flag that makes bsd_glob stop (rather than skip) on unreadable directories.

  • GLOB_NOSPACE, GLOB_ABEND - the two non-zero values it returns.