[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Folder recursion and recognition problem



At 08:13 96-06-03, Ben Ko wrote:

>I have a feeling it's something quite basic staring me in the face but i'm
>just not seeing it. If anyone can point me to a source, or can spot the
>problem, that would be great.

Yep.  It's one of those simple things that catches all of us.  The Perl
function opendir() does NOT imply a chdir().  Further, all the
filenames returned by readdir() are not fully qualified.

This means you should either:
a) do a chdir() to the supplied directory, then always do an opendir()
on the current directory (':' for Mac, '.' for unix/dos).  Or,
b) always prepend the directory to the filename returned by readdir().

My hunch is (a) runs faster on the Mac (due to internals of the Mac
file system), and no slower on other file systems.  However, (b) avoids
the side effect of changing the working directory for the rest of the
script (which may not be a problem in your case.

(What you're seeing in your described behavior is that the directories
don't test as directories because they don't exist in the current
directory unless the applet is also in that directory.  If you'd added
the code:
    die( "Can't find '$_' in '$dir'\n" ) unless -e $_;
you'd have tumbled to the problem.)

--Hal
Hal Wine <hal@dtor.com>     voice: 510/482-0597