-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
<br/>
On Tue, November 15, 2005 13:31, Theodore Katseres wrote:<br/>
> It appears that no recursion is happening passed the initial dive.
{<br/>
> ProcFiles("/tmp") }<br/>
<br/>
I agree -- when I take out the '<span
class="Code">&ProcFiles("$dir/$file");</span>' line, it
continues through the /tmp directory fine. With the recursive call
to itself, I can watch the script dive into the sub-directory (/tmp/dir1),
and it processes all the files in /tmp/dir1, but when it finishes with the
files in "dir1" the program quits. Unless I am missing
something, I thought it should go back one level to the initial invocation
of ProcFiles and continue where it left off there...<br/>
<br/>
> Check my comments.<br/>
> <br/>
> <Snip && Replace><br/>
> #!/bin/perl -w<br/>
> use strict;<br/>
> <br/>
> sub ProcFiles {<br/>
> my $dir = shift;<br/>
> <br/>
> opendir( DIR, $dir ) or die $!;<br/>
> <br/>
> while ( my $file = readdir(DIR) ) {<br/>
> <br/>
> next if ( -d "$dir/$file" && $file =~ /^\./
);<br/>
> <br/>
> # above makes sure this block of code never gets executed<br/>
<br/>
The line you mention ("next if ...") is used to make sure I skip
the "." and ".." entries in the subdirectory --
otherwise it would back out of the "/tmp" to "/" and
work there! :( (It also has the effect of ignoring files with a
leading "." -- that's also by design.)<br/>
<br/>
> if ( -d "$dir/$file" ) {<br/>
> <br/>
> printf( "Diving into\"%s/%s\".\n",
$dir, $file );<br/>
> <br/>
> &ProcFiles("$dir/$file");<br/>
> <br/>
> next;<br/>
> <br/>
> }<br/>
> <br/>
> # your printing files that don't begin with "."<br/>
<br/>
True -- in my real script, this print line is replaced with a small bit of
code to do some real work! In the example I posted to OLUG I wanted to
keep it simple and see if I could make it work...<br/>
<br/>
> printf( "Adding\"%s/%s\".\n", $dir, $file
);<br/>
> <br/>
> }<br/>
> <br/>
> closedir(DIR);<br/>
> <br/>
> }<br/>
> <br/>
> &ProcFiles("/tmp");<br/>
<br/>
Ted, thanks for your input.<br/>
<br/>
Dan<br/>
<br/>
- - - - -<br/>
"Wait for that wisest of all counselors, time." -- Pericles<br/>
"I do not fear computer, I fear the lack of them." -- Isaac
Asimov<br/>
GPG fingerprint:6FFD DB94 7B96 0FD8 EADF 2EE0 B2B0 CC47 4FDE 9B68
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDejqusrDMR0/em2gRAtT2AJ9cL6zR+u/XpmGtjXNCCM/Y9WDcvwCfY1Fp
qXscyNVDA6vb5H8MuKUrEtM=
=mFaZ
-----END PGP SIGNATURE-----