fail to recursive by Perl while
<p>I'm trying to write a function recursively searching for all the directories under a given directory. </p>

<pre><code>use strict;
use warnings;



sub printDir
{
        my $root = shift;

        opendir DIR, $root or die "can't open dir $root\n";
        my $dir;
        while ($dir = readdir DIR)
        {

                if (-d "$root/$dir" &amp;&amp; "$dir" ne '.' &amp;&amp; "$dir" ne '..')
                {
                        print "$dir\n";
                        &amp;printDir ("$root/$dir");
                }
        }

}


my $root = $ARGV[0];
printDir $root;
</code></pre>

<p>If the directory hierarchy is like:</p>

<pre><code>  A
 / \
B   C
|
D
</code></pre>

<p>The code stops after searching for A-B-D and C will not be searched. What's wrong with the code? </p>

<p>Thanks</p>