develooper Front page | perl.perl5.porters | Postings from October 2011

Re: [perl #96116] File::Glob ':glob' causes infinite loop

Thread Previous | Thread Next
From:
Tom Christiansen
Date:
October 26, 2011 08:55
Subject:
Re: [perl #96116] File::Glob ':glob' causes infinite loop
Message ID:
30641.1319644521@chthon
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About