@@ -3353,12 +3353,32 @@ X<glob> X<wildcard> X<filename, expansion> X<expand>
3353
3353
=for Pod::Functions expand filenames using wildcards
3354
3354
3355
3355
In list context, returns a (possibly empty) list of filename expansions on
3356
- the value of EXPR such as the standard Unix shell F</bin/csh> would do. In
3356
+ the value of EXPR such as the Unix shell Bash would do. In
3357
3357
scalar context, glob iterates through such filename expansions, returning
3358
- undef when the list is exhausted. This is the internal function
3359
- implementing the C<< <*.c> >> operator, but you can use it directly. If
3360
- EXPR is omitted, L<C<$_>|perlvar/$_> is used. The C<< <*.c> >> operator
3361
- is discussed in more detail in L<perlop/"I/O Operators">.
3358
+ L<C<undef>|/undef EXPR> when the list is exhausted. If EXPR is omitted,
3359
+ L<C<$_>|perlvar/$_> is used.
3360
+
3361
+ # List context
3362
+ my @txt_files = glob("*.txt");
3363
+ my @perl_files = glob("*.pl *.pm");
3364
+
3365
+ # Scalar context
3366
+ while (my $file = glob("*.mp3")) {
3367
+ # Do stuff
3368
+ }
3369
+
3370
+ Glob also supports an altnernate syntax using C<< < >> C<< > >> as
3371
+ delimiters. While this syntax is supported, it is recommended that you
3372
+ use C<glob> instead as it is more readable and searchable.
3373
+
3374
+ my @txt_files = <"*.txt">;
3375
+
3376
+ If you need case insensitive file globbing that can be achieved using the
3377
+ C<:nocase> parameter of the L<C<bsd_glob>|File::Glob/C<bsd_glob>> module.
3378
+
3379
+ use File::Glob qw(:globally :nocase);
3380
+
3381
+ my @txt = glob("readme*"); # README readme.txt Readme.md
3362
3382
3363
3383
Note that L<C<glob>|/glob EXPR> splits its arguments on whitespace and
3364
3384
treats
@@ -3371,23 +3391,23 @@ For example, to glob filenames that have an C<e> followed by a space
3371
3391
followed by an C<f>, use one of:
3372
3392
3373
3393
my @spacies = <"*e f*">;
3374
- my @spacies = glob '"*e f*"';
3375
- my @spacies = glob q("*e f*");
3394
+ my @spacies = glob( '"*e f*"') ;
3395
+ my @spacies = glob( q("*e f*") );
3376
3396
3377
3397
If you had to get a variable through, you could do this:
3378
3398
3379
- my @spacies = glob "'*${var}e f*'";
3380
- my @spacies = glob qq("*${var}e f*");
3399
+ my @spacies = glob( "'*${var}e f*'") ;
3400
+ my @spacies = glob( qq("*${var}e f*") );
3381
3401
3382
3402
If non-empty braces are the only wildcard characters used in the
3383
3403
L<C<glob>|/glob EXPR>, no filenames are matched, but potentially many
3384
3404
strings are returned. For example, this produces nine strings, one for
3385
3405
each pairing of fruits and colors:
3386
3406
3387
- my @many = glob "{apple,tomato,cherry}={green,yellow,red}";
3407
+ my @many = glob( "{apple,tomato,cherry}={green,yellow,red}") ;
3388
3408
3389
3409
This operator is implemented using the standard C<File::Glob> extension.
3390
- See L<File::Glob> for details, including
3410
+ See L<C<bsd_glob>| File::Glob/C<bsd_glob> > for details, including
3391
3411
L<C<bsd_glob>|File::Glob/C<bsd_glob>>, which does not treat whitespace
3392
3412
as a pattern separator.
3393
3413
@@ -3398,6 +3418,12 @@ is used as a C<while>/C<for> condition, then the condition actually
3398
3418
tests for definedness of the expression's value, not for its regular
3399
3419
truth value.
3400
3420
3421
+ Internal implemenation details:
3422
+
3423
+ This is the internal function implementing the C<< <*.c> >> operator,
3424
+ but you can use it directly. The C<< <*.c> >> operator is discussed in
3425
+ more detail in L<perlop/"I/O Operators">.
3426
+
3401
3427
Portability issues: L<perlport/glob>.
3402
3428
3403
3429
=item gmtime EXPR
0 commit comments