Jeff Westman wrotenews:[EMAIL PROTECTED] > Hi, > > I've never liked "recursion" but of course there are times where it is > needed. > > I have a simple task that I am trying to do. Basically, I just want to list > out my directories on disk, and then chdir to each one, print it out, and so > on. Pretty basic, but I have a total mental block using recursion. > > Any quick help or tips would be appreciated.
Hi Jeff. File::Find would do it for you, but the revursion is very simple really: use strict; use warnings; printdir('/usr'); sub printdir { my $dir = shift; opendir DIR, $dir or die $!; my @dirs = grep /[^.]/, readdir DIR; closedir DIR; foreach (map "$dir/$_", @dirs) { if (-d) { printdir($_); } elsif (-f _) { print $_, "\n"; } } } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]