Re: Problem with glob and filenames containing '[' and ']'



David Squire <David.Squire@xxxxxxxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
anno4000@xxxxxxxxxxxxxxxxxxxxxx wrote:
David Squire <David.Squire@xxxxxxxxxxxxxxxxxxxx> wrote in
comp.lang.perl.misc:
Hi folks,

I'm having trouble using glob to find filenames that contain '[' and
']', even though I am escaping those meta-characters. Here is an example
script and output:

I don't know what goes wrong for you. It works for me as expected
(after replacing /damocles/documents/ENH1260/2006/2/Short assignment/
with something that exists on my box).

Thanks. Would you be able to try my second, simpler, example too? That
seems to narrow down the oddness.

Well yes, it's the blank in the path name that does it. Here is the
relevant bit from File::Glob, which implements CORE::glob():

Since v5.6.0, Perl's CORE::glob() is implemented in terms of
bsd_glob(). Note that they don't share the same proto-
type--CORE::glob() only accepts a single argument. Due to historical
reasons, CORE::glob() will also split its argument on whitespace,
treating it as multiple patterns, whereas bsd_glob() considers them as
one pattern.

So it's not a bug. The solution would be to use File::Glob::bsd_glob()
directly.

Anno
.



Relevant Pages

  • Re: Problem with glob and filenames containing [ and ]
    ... I'm having trouble using glob to find filenames that contain '[' and ... even though I am escaping those meta-characters. ... script and output: ...
    (comp.lang.perl.misc)
  • Re: Problem with glob and filenames containing [ and ]
    ... I'm having trouble using glob to find filenames that contain '[' and ... even though I am escaping those meta-characters. ... I think that's going to confuse glob big-time. ...
    (comp.lang.perl.misc)
  • Re: Newbie: Joining Lists
    ... there a better way of getting GLOB to recognise, multiple patterns at ... perusal of the docs for the glob module shows that glob uses some very ... filenames += glob.glob ...
    (comp.lang.python)