in reply to How glob expands
Because that's the way shells do it and File::Glob (and glob as of not-so-recent versions) uses the BSD csh (I believe) globbing implementation.
It might help to think of the character class being a predicate ("Is there a file present in the cwd which has one of these characters at the position in question?"), whereas the curly braces work more as a pattern that you're asking the globbing engine to generate irrespective of the contents of the current working directory ("Give me a list made up of items with the un-braced portion followed by each of the alternatives.").
Yes, it's nonintuitive. But that's the way it works.
Update: Durr, says right on the label: Post 5.6.0 glob is implemented with File::Glob, and I want to say the BSD-based C implementation was made at the same time. So glob should behave more-or-less the same way everywhere for not-unreasonably-old perls.
Shell example: Just as way of proof, here's the way zsh (another shell which implements csh-esque globbing) behaves. Prior to the first command there's no files in the directory.
$ zsh -c 'print foo{a,b}' fooa foob $ zsh -c 'print foo[a,b]' zsh: no matches found: foo[ab] $ touch fooa $ zsh -c 'print foo[ab]' fooa
Just remember that [] is a predicate on directory contents, {} is dumb pattern expansion.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How glob expands
by calin (Deacon) on Sep 29, 2007 at 18:43 UTC |