E
ed
I have the following code and I'm trying to understand it a little
better, can anyone help?
#!/usr/bin/perl
$startdir = "/lib";
$level = 0;
list_dirs($startdir,$level);
sub list_dirs(){
my $dir = shift (@_);
my $lev = shift (@_);
opendir(TOP,$dir);
my @files = readdir(TOP);
closedir(TOP);
shift(@files);
shift(@files);
foreach $file (@files){
if(-d "$dir/$file"){
spaces($lev);
print "$file\n";
list_dirs("$dir/$file",$lev+1);
}
}
}
sub spaces(){
my($num) = shift(@_);
for($i=0;$i<$num;$i++){
print " ";
}
}
I understand in the foreach statement that it is calling the sub
routine "spaces($lev),
I'm trying to understand the sub routine "spaces", how is it making my
subdirectories indent?
better, can anyone help?
#!/usr/bin/perl
$startdir = "/lib";
$level = 0;
list_dirs($startdir,$level);
sub list_dirs(){
my $dir = shift (@_);
my $lev = shift (@_);
opendir(TOP,$dir);
my @files = readdir(TOP);
closedir(TOP);
shift(@files);
shift(@files);
foreach $file (@files){
if(-d "$dir/$file"){
spaces($lev);
print "$file\n";
list_dirs("$dir/$file",$lev+1);
}
}
}
sub spaces(){
my($num) = shift(@_);
for($i=0;$i<$num;$i++){
print " ";
}
}
I understand in the foreach statement that it is calling the sub
routine "spaces($lev),
I'm trying to understand the sub routine "spaces", how is it making my
subdirectories indent?