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

Try testing your data for 'globbable' characters. (My list of '*' and ? is probably incomplete.)
#! /usr/bin/perl -w $, = ', '; print $ARGV[0] =~ tr/*?// ? glob ($ARGV[0]) : ((-e $ARGV[0]) ? $ARGV[0 +] : '<No File>');

This was tested on Win32 so $ARGV[0] is not globbed by the OS.

Also try the following which atempts a glob followed by a single file test in case you were globbing a normal file name.

#! /usr/bin/perl -w $, = ', '; my @files = glob('*.txt'); print @files if -e $files[0];

Replies are listed 'Best First'.
•Re: Re: Test for file(s): glob or -e?
by merlyn (Sage) on Feb 18, 2004 at 15:27 UTC
      My Windows background has found me out...
      $, = ', '; my @files; print ((-e $data)? $data : ((@files = glob $data) && ($data ne $files[ +0]))? @files : ()) if $data;

      Prints $data if $data is a file. Prints the globbed $data only if the glob did some work. The whole statement is protected just in case $data is empty.