Skip to content

Commit

Permalink
Add some examples to the glob() documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
scottchiefbaker committed May 26, 2021
1 parent 97b09ac commit 8de26a8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pod/perlfunc.pod
Expand Up @@ -3372,11 +3372,19 @@ X<glob> X<wildcard> X<filename, expansion> X<expand>
In list context, returns a (possibly empty) list of filename expansions on
the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
scalar context, glob iterates through such filename expansions, returning
undef when the list is exhausted. This is the internal function
implementing the C<< <*.c> >> operator, but you can use it directly. If
undef when the list is exhausted. If
EXPR is omitted, L<C<$_>|perlvar/$_> is used. The C<< <*.c> >> operator
is discussed in more detail in L<perlop/"I/O Operators">.

# List context
my @txt_files = glob("*.txt");
my @perl_files = glob("*.pl *.pm");

# Scalar context
while (my $file = glob("*.mp3")) {
# Do stuff
}

Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and
treats
each segment as separate pattern. As such, C<glob("*.c *.h")>
Expand Down Expand Up @@ -3415,6 +3423,12 @@ is used as a C<while>/C<for> condition, then the condition actually
tests for definedness of the expression's value, not for its regular
truth value.

Internal implemenation details:

In scalar context this is the internal function implementing the
C<< <*.c> >> operator, but you can use it directly. The C<< <*.c> >>
operator is discussed in more detail in L<perlop/"I/O Operators">.

Portability issues: L<perlport/glob>.

=item gmtime EXPR
Expand Down

0 comments on commit 8de26a8

Please sign in to comment.