Cari di Perl 
    Perl User Manual
Daftar Isi
(Sebelumnya) File control system callSystem-dependent device contro ... (Berikutnya)
Functions for filehandles, files, or directories

Expand filenames using wildcards

Daftar Isi

  • glob EXPR

  • glob

    In list context, returns a (possibly empty) list of filename expansions onthe value of EXPR such as the standard Unix shell /bin/csh would do. Inscalar context, glob iterates through such filename expansions, returningundef when the list is exhausted. This is the internal functionimplementing the <*.c> operator, but you can use it directly. IfEXPR is omitted, $_ is used. The <*.c> operator is discussed inmore detail in I/O Operators in perlop.

    Note that glob splits its arguments on whitespace and treatseach segment as separate pattern. As such, glob("*.c *.h") matches all files with a .c or .h extension. The expressionglob(".* *") matches all files in the current working directory.If you want to glob filenames that might contain whitespace, you'llhave to use extra quotes around the spacey filename to protect it.For example, to glob filenames that have an e followed by a spacefollowed by an f, use either of:

    1. @spacies = <"*e f*">;
    2. @spacies = glob '"*e f*"';
    3. @spacies = glob q("*e f*");

    If you had to get a variable through, you could do this:

    1. @spacies = glob "'*${var}e f*'";
    2. @spacies = glob qq("*${var}e f*");

    If non-empty braces are the only wildcard characters used in theglob, no filenames are matched, but potentially many stringsare returned. For example, this produces nine strings, one foreach pairing of fruits and colors:

    1. @many = glob "{apple,tomato,cherry}={green,yellow,red}";

    Beginning with v5.6.0, this operator is implemented using the standardFile::Glob extension. See File::Glob for details, includingbsd_glob which does not treat whitespace as a pattern separator.

    Portability issues: glob in perlport.

 
Source : perldoc.perl.org - Official documentation for the Perl programming language
Site maintained by Jon Allen (JJ)     See the project page for more details
Documentation maintained by the Perl 5 Porters
(Sebelumnya) File control system callSystem-dependent device contro ... (Berikutnya)