in reply to a glob w/ no wildcards returns itself

While you can certainly argue for (or against) any of the different globbing behaviors - ranging from "the shell"'s (interpret wildcards literally, if no match in the file system) to Python's (always test for existence) - ultimately, it's a matter of preference.

Personally, I find Perl's mixed behavior rather "do-what-I-mean".  I.e., when I specify a ? or * wildcard, I'm typically interested in what matching files there are in the file system, while if I use a "limited set" wildcard like {a,b,c}, I can compactly compute permutations with it, e.g.

$ perl -le 'print for glob "{foo,bar}{baz,quux}"' foobaz fooquux barbaz barquux

which Python doesn't do because of its consistent behavior.  IOW, consistent isn't always the most practically useful... :)

And, as for the shell, I always found its behavior to treat a "*" literally (in case nothing matches) a little counter-intuitive... (if I really mean a literal "*", I can always escape it in Perl).

Anyhow, YMMV.

Replies are listed 'Best First'.
Re^2: a glob w/ no wildcards returns itself
by jeberle (Initiate) on Aug 23, 2011 at 19:32 UTC
    Thank you Eliya. The use case I have is to do actual file matching, where the user specifies the pattern. For this, the behavior is counter-productive. Therefore:
    $ perl -le 'print grep { -f } glob "foo.c"'
    will have to rule the day.

    In bash you can do:

    $ shopt -s nullglob $ echo foo.?
    but then ls generates full dir listings on failed globs.