Re: glob problem: escaped space seems to be significant too (was Re: Problem with glob and filenames containing '[' and ']')



On 09/27/2006 08:43 AM, David Squire wrote:
David Squire wrote:
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:

Hi again,

I have reduced this further, getting rid of de-url and a bunch of other
stuff related to my original context. Please see the reduced script and
output below. It seems that having an escaped space as well as an escape
'[' causes the failure to match. See the third last test case.

I hesitate to say it, but this begins to feel like a bug... (covers head).

----


#!/usr/bin/perl

use strict;
use warnings;

print "Directory contents:\n", `ls -1 f*`, "\n";
for my $GlobPattern (
'fred*',
'fred[1]*',
'fred\[1\]*',
'fred\[1]*',
'fred[1\]*',
'fre\ d*',
'fre\ d\[*',
'fre\ d\[1*',
'fre\ d\[1\]*',
'fre?d\[1\]*',
'fre\ d?1\]*',
) {
my @CandidateOrigFiles = glob ($GlobPattern);
print "\n######################################\n";
print "$GlobPattern: \@CandidateOrigFiles:\n", join "\n",
@CandidateOrigFiles;
}

----

Output:

Directory contents:
fred]
fred[1]
fre d[1].doc
fred[[1].doc
fred[1].doc


######################################
fred*: @CandidateOrigFiles:
fred[1]
fred[1].doc
fred[[1].doc
fred]

Correct

######################################
fred[1]*: @CandidateOrigFiles:


Correct. This would match "fred1" or "fred19" because the unescaped [] pair creates a character class (globbing-style).


######################################
fred\[1\]*: @CandidateOrigFiles:
fred[1]
fred[1].doc

Correct

######################################
fred\[1]*: @CandidateOrigFiles:
fred[1]
fred[1].doc

I think this is correct, but I'm not sure.

######################################
fred[1\]*: @CandidateOrigFiles:
fred[1]
fred[1].doc

What? That doesn't look right to me. The "[" should start a character class.


######################################
fre\ d*: @CandidateOrigFiles:
fre d[1].doc

Correct

######################################
fre\ d\[*: @CandidateOrigFiles:
fre d[1].doc

Correct

######################################
fre\ d\[1*: @CandidateOrigFiles:
fre d[1].doc

Correct

######################################
fre\ d\[1\]*: @CandidateOrigFiles:


Hmm, "fre d[1].doc" should appear.

######################################
fre?d\[1\]*: @CandidateOrigFiles:
fre d[1].doc

Correct

######################################
fre\ d?1\]*: @CandidateOrigFiles:
fre d[1].doc


Correct

----

DS

Clearly, an escaped space does not cause the problem. It has something to do with both an escaped space and an escaped bracket.

--
paduille.4058.mumia.w@xxxxxxxxxxxxx
.



Relevant Pages