There are two functions you can use to get the contents
of a directory. glob and readdir. glob is
the slowest, but allows you to limit the types of files
you get back. eg
my @files = glob("*_hm1_111");
will return you all files ending with hm1_111, but you need
more flexibility than this, so readdir is probably the best
choice.
readdir on the other hand is very fast, and returns you the
files in whatever order they are stored in the internal
representation for your file system. This will not always
be alpha/ascii-betical. glob always returns files sorted
ascii-betically.
The last difference between the two is how . (dot)
files are handled. glob("*") will not return files such as
.bashrc but readdir will. glob(".*") must be called
if you want the . files. (In fact glob works very
much like the UNIX c-shell.)
Having said all of this, I'd suggest you use ovid's
suggestion in most circumstances. However, if it is likely
that your directory contents will be very large (and you
are only interested in a small fraction of the files) and if
performance is important then I'd suggest you compare ovid's
suggestion with something like this:
my @files = grep /^(?:ap|ck)_hm1_111/, glob("DIR/*_hm1_111");
and go with the best.
Jacinta |