Re: Problem with glob and filenames containing '[' and ']'
- From: David Squire <David.Squire@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Sep 2006 19:02:58 +0100
anno4000@xxxxxxxxxxxxxxxxxxxxxx wrote:
David Squire <David.Squire@xxxxxxxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:anno4000@xxxxxxxxxxxxxxxxxxxxxx wrote:David Squire <David.Squire@xxxxxxxxxxxxxxxxxxxx> wrote incomp.lang.perl.misc:Thanks. Would you be able to try my second, simpler, example too? ThatHi folks,I don't know what goes wrong for you. It works for me as expected
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:
(after replacing /damocles/documents/ENH1260/2006/2/Short assignment/
with something that exists on my box).
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.
Thanks for drawing my attention to this. Very non-intuitive and non-shell-like, despite what perldoc -f glob says.
I am also puzzled that quite a few of my test cases (in my second post with example code) including escaped blanks worked exactly as I would have expected. For example (from that post), with files present:
fred]
fred[1]
fre d[1].doc
fred[[1].doc
fred[1].doc
I get, in one case:
######################################
fre\ d*: @CandidateOrigFiles:
fre d[1].doc
I can't see how that would happen if the parts of the pattern on each side of the blank were treated as separately - but would be glad to be enlightened.
The much larger script from which this is distilled, also worked as I expected in almost all cases. I have thousands of cases, all with a blank in the path, where there is no problem. It only arises in combination with \[ and \] (and some of those files have other escaped characters).
I have now written a work-around using opendir/readdir, but still find this odd.
DS
.
- References:
- Problem with glob and filenames containing '[' and ']'
- From: David Squire
- Re: Problem with glob and filenames containing '[' and ']'
- From: anno4000
- Re: Problem with glob and filenames containing '[' and ']'
- From: David Squire
- Re: Problem with glob and filenames containing '[' and ']'
- From: anno4000
- Problem with glob and filenames containing '[' and ']'
- Prev by Date: Re: Problem with glob and filenames containing '[' and ']'
- Next by Date: Re: WIn32API and keyboard
- Previous by thread: Re: Problem with glob and filenames containing '[' and ']'
- Next by thread: Re: Problem with glob and filenames containing '[' and ']'
- Index(es):
Relevant Pages
|