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

What I'm looking for is a single test to use if I don't know ahead of time if the string will refer to a single file or a shell pattern.
You can't know. A file named abc[d]e is perfectly legal, and yet using that string as a glob won't match that filename!

You have to change your spec so that it is clear whether the string is a literal or a pattern. Anything else is going to get you into trouble.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Test for file(s): glob or -e?
by delirium (Chaplain) on Feb 18, 2004 at 18:37 UTC
    Changing the spec it is, then. I can enforce a 'files must have no shell wildcard characters in their names' policy with this.

    With that in mind, and after thinking over the problem some more, I came up with a test (update: the same test the ysth beat me to by 3 minutes) that seems to work:

    if ( grep {-e} glob $file ) {...

    In this way, if $file is a single filename that doesn't exist, it will fail on the -e test. If $file is multiple files, glob will see them all.