in reply to Test for file(s): glob or -e?

I have to agree with merlyn (not that it's a struggle :) that you should specify that your input is either a filename or a glob pattern, but maybe this will help:
# get the names if any @files = grep -e, glob $pattern;
or
# do any exist? if (grep -e, glob $pattern) {...

Replies are listed 'Best First'.
Re: Re: Test for file(s): glob or -e?
by Anonymous Monk on Feb 18, 2004 at 18:44 UTC

    *boggles*

    Why grep -e? Does glob make up stuff that doesn't exist in the directory now?

      By design, glob only checks for actual existence of files if you include * or ? in that part of the path:
      $ echo hi there>foo $ ls foo $ perl -wle'print for glob "{a,b,c,}fo{*,}"' afo bfo cfo foo fo
      This pattern expands to {afo,bfo,cfo,fo,afo*,bfo*,cfo*,fo*}. Only the subpatterns containing a ? or * will be restricted to what exists. In the simple case, glob "joe.txt" will always return joe.txt.