This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlfunc/glob: Explain use of quotes
authorTom Christiansen <tchrist@perl.com>
Mon, 31 Oct 2011 16:59:11 +0000 (09:59 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 31 Oct 2011 20:16:57 +0000 (13:16 -0700)
pod/perlfunc.pod

index 6a09a53..4ce4be3 100644 (file)
@@ -2536,6 +2536,19 @@ Note that C<glob> splits its arguments on whitespace and treats
 each segment as separate pattern.  As such, C<glob("*.c *.h")> 
 matches all files with a F<.c> or F<.h> extension.  The expression
 C<glob(".* *")> matches all files in the current working directory.
+If you want to glob filenames that might contain whitespace, you'll
+have to use extra quotes around the spacey filename to protect it.
+For example, to glob filenames that have an C<e> followed by a space
+followed by an C<f>, use either of:
+
+    @spacies = <"*e f*">;
+    @spacies = glob '"*e f*"';
+    @spacies = glob q("*e f*");
+
+If you had to get a variable through, you could do this:
+
+    @spacies = glob "'*${var}e f*'";
+    @spacies = glob qq("*${var}e f*");
 
 If non-empty braces are the only wildcard characters used in the
 C<glob>, no filenames are matched, but potentially many strings