Perl Programming/Keywords/glob

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Previous: given Keywords Next: gmtime

The glob keyword[edit | edit source]

glob returns in list context a (probably empty) list of filename extensions on the value of EXPRESSION. Called in scalar context, it iterates through such filename expansions and returns undef when the list is exhausted. If EXPRESSION is omitted, $_ is used instead.

glob splits its arguments on whitespace and treats each segment as a separate pattern.

Syntax[edit | edit source]


Examples[edit | edit source]

The code
@array = glob("*.pl *.txt");

foreach (@array) {
  print "$_\n";
returns all Perl files in the directory:

Previous: given Keywords Next: gmtime