in reply to Why does File::Find chdir?
This simple, obvious code doesn't do what I expect. The reason is that I keep forgetting to explictly do a chdir($dir): the "-d" is looking in the wrong place. So myself, I've been wondering why an "opendir" doesn't do a "chdir" for you... You can do the recursive equivalent of that task using File::Find like so:# Find all sub-dirs of $dir opendir DIR, $dir or die "yaddah:$!"; @subdirs = grep { -d } readdir(DIR);
Without the implicit "chdir" behavior, you'd need to change the "-d" line to:use File::Find; find( sub { -d && print $File::Find::name, "\n"; }, $dir );
-d $File::Find::name && print $File::Find::name, "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why does File::Find chdir? (glob++)
by tye (Sage) on Jul 14, 2004 at 00:32 UTC |