in reply to As usual
in thread Recursive directory scanning

I don't see any subdirectory building anywhere. When you ask for the directories under "/home", you're getting back "merlyn" and "vroom", not "/home/merlyn" and "/home/vroom". So you then recurse on just "merlyn", and the opendir fails.

To do that portably, you need to look at File::Spec, since Unix wants forward slash, Windows can handle forward slash but most people expect backslash, Macs want colon, and VMS wants some mixed up mess.

But then you also have to figure out how to skip over symlinks, since that can send you into an infinite loop by turning a DAG into a general node map, bringing you back to where you started too fast.

You also didn't localize your directory handle. In the way you used it, it wouldn't have hurt you, but it it could have potentially stomped on any other use of the same name.

So this is why "recursive directory handling" is nearly always responded with a groan, a sigh, and "please use File::Find". It's an easy task to consider, but a difficult task to actually do right.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Thanks
by pwhysall (Acolyte) on Mar 01, 2001 at 19:35 UTC
    Actually, VMS just wants . separated directory names inside square brackets, with a prepended . if you want to explicitly state that it's relative to your current location, and appended ellipsis ... if you mean "this directory and everything below it". [.home.peter.stuff...]*.*;*, for example, would be roughly analogous to ./home/peter/stuff/*.*, but there's no comparable operator in UNIX for the ... bit.

    Simple, see?

    (Yes, I am a VMS admin:-)

    Thanks for the other stuff, but I really don't know what a DAG or a node map is - however, I avoid that in this case by running on Win32, which doesn't have those pesky symlinks.

    But I will definitely be using File::Find.