Of course, you could make things much simpler and just cycle through all the directories with numbers 0 through x, where x is the maximum possible value:use strict; use warnings; my ($dir, $handle, %mlc, @files, @spider); my $fname = "mlc"; # Main directory to start spidering... push @spider, ':'; while ($dir = shift @spider) { if (-e "$dir$fname") { open($handle, "$dir$fname"); $mlc{$dir} = join '', <$handle>; close($handle); } opendir($handle, $dir); @files = readdir($handle); closedir($handle); for (@files) { push @spider, "$dir$_:" if -d "$dir$_"; } } for (sort keys %mlc) { print "$_\n$mlc{$_}\n\n"; }
use strict; use warnings; my (%mlc, $handle); for (0..200) { if (-e ":dir$_:mlc") { open($handle, ":dir$_:mlc"); $mlc{"dir$_"} = join '', <$handle>; close($handle); } } for (sort keys %mlc) { print "$_\n$mlc{$_}\n\n"; }
In reply to Re: opening directories in perl
by TedPride
in thread opening directories in perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |