Hi,

it was hard to see the blue stuff.. :)


On Wed, 4 Jul 2007 16:14:47 +0300
"Amichai Teumim" <[EMAIL PROTECTED]> wrote:

> #!/usr/bin/perl
> 
> $startdir = "/lib";
> 
> $level = 0;
> 
> list_dirs($startdir,$level);

calls &list_dir with $startdir and $level.


> 
> sub list_dirs(){
>   my $dir  = shift (@_);
>   my $lev = shift (@_);

shift $dir and $level out of the stack.

> 
> 
>   opendir(TOP,$dir);
>   my @files = readdir(TOP);
>   closedir(TOP);

opens the directory and reads the content into @files;

> 
>   shift(@files);
>   shift(@files);

removes the first 2 elements: "." and ".."

> 
>   foreach $file (@files){

for each file in the directory

>     if(-d "$dir/$file"){

is the file a dir?

>         spaces($lev);
prints $lev spaces: print " " x $lev; #would do tha same
and print the filename ( directory name ).
>         print "$file\n"; 


does the same stuff for the new direktory
since $level is increased by one whole output will be indented 
>         list_dirs("$dir/$file",$lev+1);
>     }
>   }
> 
> }
> 

same as print " " x $lev;
> sub spaces(){
>   my($num) = shift(@_);
>   for($i=0;$i<$num;$i++){
>     print " ";
>   }
> }


HTH, Martin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to