Manual Pages for UNIX Darwin command on man File::Glob
MyWebUniversity

Manual Pages for UNIX Darwin command on man File::Glob

File::Glob(3pm) Perl Programmers Reference Guide File::Glob(3pm)

NAME

File::Glob - Perl extension for BSD glob routine

SYNOPSIS

use File::Glob ':glob';

@list = bsdglob('*.[ch]');

$homedir = bsdglob('~gnat', GLOBTILDE | GLOBERR);

if (GLOBERROR) {

# 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/*>;

DESCRIPTION

The glob angle-bracket operator "<>" 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.

File::Glob::bsdglob() implements the FreeBSD glob(3) routine, which is

a superset of the POSIX glob() (described in IEEE Std 1003.2 "POSIX.2"). bsdglob() 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. Since v5.6.0, Perl's CORE::glob() is implemented in terms of

bsdglob(). Note that they don't share the same proto-

type-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 bsdglob() considers them as one pattern. MMEETTAA CCHHAARRAACCTTEERRSS \ Quote the next metacharacter [] Character class {} Multiple pattern * Match any string of characters ? Match any single character ~ User name home directory The metanotation "a{b,c,d}e" is a shorthand for "abe ace ade". Left to

right order is preserved, with results of matches being sorted sepa-

rately at a low level to preserve this order. As a special case "{", "}", and "{}" are passed undisturbed. PPOOSSIIXX FFLLAAGGSS The POSIX defined flags for bsdglob() are: "GLOBERR" Force bsdglob() to return an error when it encounters a directory it cannot open or read. Ordinarily bsdglob() continues to find matches. "GLOBLIMIT" Make bsdglob() return an error (GLOBNOSPACE) when the pattern

expands to a size bigger than the system constant "ARGMAX" (usu-

ally found in limits.h). If your system does not define this con-

stant, bsdglob() uses "sysconf(SCARGMAX)" or "POSIXARGMAX" where available (in that order). You can inspect these values using the standard "POSIX" extension. "GLOBMARK" Each pathname that is a directory that matches the pattern has a slash appended. "GLOBNOCASE" By default, file names are assumed to be case sensitive; this flag makes bsdglob() treat case differences as not significant. "GLOBNOCHECK" If the pattern does not match any pathname, then bsdglob() returns a list consisting of only the pattern. If "GLOBQUOTE" is set, its effect is present in the pattern returned. "GLOBNOSORT" By default, the pathnames are sorted in ascending ASCII order; this flag prevents that sorting (speeding up bsdglob()). The FreeBSD extensions to the POSIX standard are the following flags: "GLOBBRACE"

Pre-process the string to expand "{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) pat-

terns). "GLOBNOMAGIC" Same as "GLOBNOCHECK" 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. "GLOBQUOTE" 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 charac-

ter. (But see below for exceptions on DOSISH systems). "GLOBTILDE" Expand patterns that start with '~' to user name home directories. "GLOBCSH" For convenience, "GLOBCSH" is a synonym for "GLOBBRACE | GLOBNOMAGIC | GLOBQUOTE | GLOBTILDE | GLOBALPHASORT".

The POSIX provided "GLOBAPPEND", "GLOBDOOFFS", and the FreeBSD exten-

sions "GLOBALTDIRFUNC", and "GLOBMAGCHAR" flags have not been imple-

mented in the Perl version because they involve more complex interac-

tion with the underlying C structures. The following flag has been added in the Perl implementation for csh compatibility: "GLOBALPHASORT" If "GLOBNOSORT" is not in effect, sort filenames is alphabetical order (case does not matter) rather than in ASCII order. DIAGNOSTICS bsdglob() returns a list of matching paths, possibly zero length. If

an error occurred, &File::Glob::GLOBERROR will be non-zero and $! will

be set. &File::Glob::GLOBERROR is guaranteed to be zero if no error

occurred, or one of the following values otherwise: "GLOBNOSPACE" An attempt to allocate memory failed. "GLOBABEND" The glob was stopped because an error was encountered. In the case where bsdglob() has found some matching paths, but is interrupted by an error, it will return a list of filenames aanndd set

&File::Glob::ERROR.

Note that bsdglob() deviates from POSIX and FreeBSD glob(3) behaviour

by not considering "ENOENT" and "ENOTDIR" as errors - bsdglob() will

continue processing despite those errors, unless the "GLOBERR" flag is set.

Be aware that all filenames returned from File::Glob are tainted.

NNOOTTEESS +o If you want to use multiple patterns, e.g. "bsdglob("a* b*")", you should probably throw them in a set as in "bsdglob("{a*,b*}")".

This is because the argument to bsdglob() isn't subjected to pars-

ing by the C shell. Remember that you can use a backslash to escape things.

+o On DOSISH systems, backslash is a valid directory separator charac-

ter. In this case, use of backslash as a quoting character (via GLOBQUOTE) 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 quot-

ing. However, this does not match "normal practice" on these sys-

tems. As a concession to user expectation, therefore, backslashes (under GLOBQUOTE) only quote the glob metacharacters '[', ']',

'{', '}', '-', '~', and backslash itself. All other backslashes

are passed through unchanged. +o 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. +o Mac OS (Classic) users should note a few differences. Since Mac OS is not Unix, when the glob code encounters a tilde glob (e.g. ~user) and the "GLOBTILDE" flag is used, it simply returns that pattern without doing any expansion.

Glob on Mac OS is case-insensitive by default (if you don't use any

flags). If you specify any flags at all and still want glob to be

case-insensitive, you must include "GLOBNOCASE" in the flags.

The path separator is ':' (aka colon), not '/' (aka slash). Mac OS users should be careful about specifying relative pathnames. While a full path always begins with a volume name, a relative pathname should always begin with a ':'. If specifying a volume name only, a trailing ':' is required. The specification of pathnames in glob patterns adheres to the usual Mac OS conventions: The path separator is a colon ':', not a slash '/'. A full path always begins with a volume name. A relative

pathname on Mac OS must always begin with a ':', except when speci-

fying a file or directory name in the current working directory, where the leading colon is optional. If specifying a volume name only, a trailing ':' is required. Due to these rules, a glob like <*:> will find all mounted volumes, while a glob like <*> or <:*> will find all files and directories in the current directory.

Note that updirs in the glob pattern are resolved before the match-

ing begins, i.e. a pattern like "*HD:t?p::a*" will be matched as "*HD:a*". Note also, that a single trailing ':' in the pattern is ignored (unless it's a volume name pattern like "*HD:"), i.e. a glob like <:*:> will find both directories and files (and not, as one might expect, only directories). You can, however, use the "GLOBMARK" flag to distinguish (without a file test) directory names from file names. If the "GLOBMARK" flag is set, all directory paths will have a ':' appended. Since a directory like 'lib:' is not a valid relative path on Mac OS, both a leading and a trailing colon will be added, when the directory name in question doesn't contain any colons (e.g. 'lib' becomes ':lib:').

SEE ALSO

"glob" in perlfunc, glob(3) AUTHOR The Perl interface was written by Nathan Torkington , and is released under the artistic license. Further modifications were

made by Greg Bacon , Gurusamy Sarathy tate.com>, and Thomas Wegner . 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. 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.

perl v5.8.8 2001-09-21 File::Glob(3pm)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™