From 8de26a865d7b987709c9bda268f4c5702a2a4847 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Wed, 26 May 2021 11:12:09 -0700 Subject: [PATCH] Add some examples to the glob() documentation --- pod/perlfunc.pod | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index e83f0fabfeb5..048caa3f5906 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -3372,11 +3372,19 @@ X X X X In list context, returns a (possibly empty) list of filename expansions on the value of EXPR such as the standard Unix shell F 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|perlvar/$_> is used. The C<< <*.c> >> operator is discussed in more detail in L. + # 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|/glob EXPR> splits its arguments on whitespace and treats each segment as separate pattern. As such, C @@ -3415,6 +3423,12 @@ is used as a C/C 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. + Portability issues: L. =item gmtime EXPR