Given:
% mkdir /tmp/sandbox
% cd /tmp/sandbox
% touch "space file" space file
% perl -E 'say for <*e f*>'
file
space
space file
file
% perl -E 'say for <"*e f*">'
space file
% perl -E '$v = "e"; say for <"*{$e} f*">'
space file
No code needs changing, only doc. I thus propose:
The C<glob> function grandfathers the use of whitespace to separate
multiple patterns such as C<< <*.c *.h> >>. 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*");
Alternately, you can use the C<File::Glob> module directly, so
for details, see its manpage. Calling C<glob> or the C<< <*> >>
operator automatically C<use>s that module, so if the module
mysteriously vaporizes from your library, an exception is raised.
--tom
Thread Previous
|
Thread Next