I've found that glob sometimes needs two backslashes in order to recognize some special characters in file names. I only tested it with []{} so far, but will do further testing. First let's prepare the field:
$ mkdir 'a{bc.d'; touch 'a{bc.d/GOT ITabcde' $ mkdir 'a {bc.d'; touch 'a {bc.d/GOT ITabcde' $ ls a {bc.d a{bc.d
Now the game begins:
$ cat foo $a=q|a\ \\\{bc.d/*|;print "pattern <", $a, "> globs to <", (glob $a), +">\n"; $ perl foo pattern <a\ \\{bc.d/*> globs to <a {bc.d/GOT ITabcde>
As soon as I prepend only one backslash to the opening curly, glob fails to expand the directory:
$ cat foo $a=q|a\ \{bc.d/*|;print "pattern <", $a, "> globs to <", (glob $a), "> +\n"; $ perl foo pattern <a\ \{bc.d/*> globs to <a >
On the other hand, it's odd that, it the file doesn't contain spaces, it suffices to use only one backslash:
$ cat foo $a=q|a\{bc.d/*|;print "pattern <", $a, "> globs to <", (glob $a), ">\n +"; $ perl foo pattern <a\{bc.d/*> globs to <a{bc.d/GOT ITabcde>
In fact, using three makes glob produce no output:
$ cat foo $a=q|a\\\{bc.d/*|;print "pattern <", $a, "> globs to <", (glob $a), "> +\n"; $ perl foo pattern <a\\{bc.d/*> globs to <a\>
This happens in all these 5 systems:
I think that the shell must be involved at some point when the pattern has spaces, so the two backslashes become one. The doc of File::Glob says something but I'm not sure it's related ("Due to historical reasons, CORE::glob() will also split its argument on whitespace, treating it as multiple patterns").
FWIW, perl, version 5.005_02 built for PA-RISC1.1 gives internal error: glob failed at foo line 1. on HP-UX td192 B.11.11 when it sees more than one backslash in a row. All four tests work as expected (ie, perform the glob correctly) if I use just one backslash. I'm downloading some old versions of Debian to test 5.6 and 5.004.
Ideas?
Update: Added perl 5.6.1.
--
David Serrano
In reply to glob with special characters by Hue-Bond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |