zavo has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to print all the files and directories within a directory(including files and directories in subdirectories. this is my code;
use strict; use warnings; use Data::Dumper; my $dir = 'C:\Users\test\Dropbox\Perl'; print_rec($dir); sub print_rec { opendir DIR, shift; while( readdir(DIR) ) { if(!/\.|\.\./ && -d $_) { print "$_ is a directory\n"; return print_rec($_); } elsif (!-d) { print "$_ \n"; } } }
My program stops after the it reaches the first deepest level, actually it not returns at the previous level. What am i doing wrong. Understanding this will help me understand how the stack trace works in perl. Thanks !!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Recursive Directory print
by karlgoethebier (Abbot) on Mar 06, 2014 at 13:37 UTC | |
Re: Recursive Directory print
by Don Coyote (Hermit) on Mar 06, 2014 at 13:18 UTC | |
Re: Recursive Directory print
by zentara (Cardinal) on Mar 06, 2014 at 15:37 UTC | |
Re: Recursive Directory print
by sn1987a (Curate) on Mar 06, 2014 at 14:17 UTC | |
by Anonymous Monk on Mar 06, 2014 at 16:52 UTC | |
Re: Recursive Directory print
by Discipulus (Canon) on Mar 06, 2014 at 12:46 UTC | |
by Laurent_R (Canon) on Mar 06, 2014 at 22:40 UTC | |
by Discipulus (Canon) on Mar 07, 2014 at 08:22 UTC | |
by Laurent_R (Canon) on Mar 07, 2014 at 19:07 UTC | |
by Discipulus (Canon) on Mar 10, 2014 at 11:27 UTC | |
| |
Re: Recursive Directory print
by Laurent_R (Canon) on Mar 06, 2014 at 18:44 UTC | |
Re: Recursive Directory print
by kcott (Archbishop) on Mar 07, 2014 at 08:50 UTC | |
Re: Recursive Directory print
by Lennotoecom (Pilgrim) on Mar 06, 2014 at 18:47 UTC | |
Re: Recursive Directory print
by zavo (Initiate) on Mar 06, 2014 at 13:07 UTC |