in reply to chdir problem

I agree with ww. This glob stuff can get you into trouble. There are a number of versions of glob(). There is even a DOS glob, one more variant to take into account when dealing with a MS platform. On one program I was able to coerce a module into using Posix glob, but couldn't make the same thing happen in main() which caused problems for file names with embedded spaces.

Using readdir and grep{} will work on any version of Perl and on any platform. Important to know is that readdir only returns the file names in the directory - not the full path name. So when you do the tests in grep{} to filter out non-directories, you have to use the full path on the -d test. Since you can use a regex inside the grep{}, you can get exactly what you want even if it is much more complex than the example below.

In general, I would advise against using cwd to change your working directory. Use full pathnames or relative pathnames from where your program is running. That way, you won't get confused about "where you are", ie where your program is running.And later in the program if you need to do something like delete some file (or perhaps make a sub-directory), you know exactly how to get a valid path name which will allow that. Plus see how much "cleaner" the code looks.

I use the following "formula"...

#!/usr/bin/perl use warnings; use strict; #list the Timepoint directories my $dir = "."; opendir (DIR, $dir) || die "couldn't open directory $dir\n"; my @TP_dirs = grep{-d "$dir/$_" && /^T/ }readdir DIR; foreach (@TP_dirs) { print "relative path of TP: $dir/$_\n"; } __END__ in my dir, prints: relative path of TP: ./TESTING