jeberle has asked for the wisdom of the Perl Monks concerning the following question:
When I supply a pattern w/o any glob characters, I get the pattern back, even if no file matches it. Why does Perl's glob do this?
$ echo foo.c foo.c $ echo foo.? foo.? $ ls foo.c ls: foo.c: No such file or directory $ ls foo.? ls: foo.?: No such file or directory $ perl -le 'print glob "foo.c"' foo.c # shell expansion w/o existence check $ perl -le 'print glob "foo.?"' # shell expansion w/ existence check
Glob's behavior w/o wildcards matches a simple shell expansion, while glob's behavior w/ wildcards matches a file existence test.
Just to make this sting a little, Python's behavior is consistent:
$ python -c 'from glob import glob; print(glob("foo.c"))' [] $ python -c 'from glob import glob; print(glob("foo.?"))' []
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: a glob w/ no wildcards returns itself
by Eliya (Vicar) on Aug 23, 2011 at 19:08 UTC | |
by jeberle (Initiate) on Aug 23, 2011 at 19:32 UTC | |
|
Re: a glob w/ no wildcards returns itself
by ikegami (Patriarch) on Aug 23, 2011 at 20:01 UTC |