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

[Omaha.pm] Perl and recursion...



-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I'm trying to setup a script to recursively step through a directory and take action on files and directories.  Pretty simple, eh? 

My script runs perfectly well and can handle the files and directory entries differently, it is only when I recursively call the subroutine that it fails.  The script recursively dives into the sub-directory, but when it is done with that directory the recursive call appears to kill the whole loop.

Here is my code -- what am I missing?

     1        #!/bin/perl -w
2 use strict;
3
4 sub ProcFiles {
5 my $dir = shift;
6
7 opendir (DIR, $dir) or die $!;
8
9 while (my $file = readdir(DIR)) {
10 next if ( -d "$dir/$file" && $file =~ /^\./);
11 if (-d "$dir/$file") {
12 printf ("Diving into \"%s/%s\".\n", $dir, $file);
13 &ProcFiles("$dir/$file");
14 next;
15 }
16
17 printf ("Adding \"%s/%s\".\n", $dir, $file);
18 }
19
20 closedir(DIR);
21 }
22
23 &ProcFiles ("/tmp");
Dan


- - - - -
"Wait for that wisest of all counselors, time." -- Pericles
"I do not fear computer, I fear the lack of them." -- Isaac Asimov
GPG fingerprint:6FFD DB94 7B96 0FD8 EADF 2EE0 B2B0 CC47 4FDE 9B68 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFDehwesrDMR0/em2gRAmPOAKCFjcQ3dUGuDjPx1jrr8xPDT57JegCgg/W6 mNoWjzNdW7e1BjjoP0x6VdE= =kDJ/ -----END PGP SIGNATURE-----