hien wrote:
dear all,

i am trying to check if there are any files named file* (e.g. file_001.txt file1.doc) in my directory.

if( -e "file*" ) { print("true\n"); } # this doesn't work
else { print("false\n"); }

if( -e "m/^file/" ) { print("true\n"); } # this doesn't work either
else { print("false\n"); }

Ouch, there's the dreaded "doesn't work"! (c.f. http://perl.plover.com/Questions4.html) Fortunately, you told us what you are after, so the question can be answered.

-e only takes a single filename.

You need a glob:

   print "Found!" if glob('file*');

Or the slightly deprecated:

   print "Found!" if <file*>;

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to