- Apr 17, 2001
- 3,650
- 0
- 76
Ok, I've worked on this thing for a while now, but still can't figure it out.  If I remove the recursive call, it runs just fine.  If I pass the sub the same thing that it's being passed in the recursive call, it works fine.  So, what's wrong?
#!/usr/bin/perl
#ask the user where they would like to delete from
print "Where would you like to begin deleting from: ";
$path = <>;
chomp($path); #remove newline
#begin deleting directories:
empty($path);
#delete the root directory, which should now be empty
#print `rm $path`;
#################################################
# sub empty
# Recursivly deletes all files and folders
#################################################
sub empty{
$path = @_[0];
print ("Checking $path\n" ;
;
#declare local variables
my @files, @subdirs;
#get directory listing
@listing = `ls -p -a $path`;
#break listing into files & subdirectories
foreach $line (@listing){
chomp($line); #remove newline
$a = chop($line);
if ($line eq ".." {
{
next; #skip parent dir
} elsif ($line eq "." {
{
next; #skip current dir
} elsif ($a eq "/" {
{
push(@subdirs,$line);
} else {
if ($a eq "@" {
{
push(@files,$line);
} else {
push(@files,$line.$a);
}
}
}
#delete all files in @files
foreach $file (@files){
print "Deleting $path/$file\n";
# print `rm $path/$file`;
}
#delete all subdirectories recursivly
foreach $subdir (@subdirs){
print "Subdirectory: $path/$subdir\n";
empty("$path/$subdir" ;
;
# print `rm $path/$subdir`;
}
}
			
			#!/usr/bin/perl
#ask the user where they would like to delete from
print "Where would you like to begin deleting from: ";
$path = <>;
chomp($path); #remove newline
#begin deleting directories:
empty($path);
#delete the root directory, which should now be empty
#print `rm $path`;
#################################################
# sub empty
# Recursivly deletes all files and folders
#################################################
sub empty{
$path = @_[0];
print ("Checking $path\n"
#declare local variables
my @files, @subdirs;
#get directory listing
@listing = `ls -p -a $path`;
#break listing into files & subdirectories
foreach $line (@listing){
chomp($line); #remove newline
$a = chop($line);
if ($line eq ".."
next; #skip parent dir
} elsif ($line eq "."
next; #skip current dir
} elsif ($a eq "/"
push(@subdirs,$line);
} else {
if ($a eq "@"
push(@files,$line);
} else {
push(@files,$line.$a);
}
}
}
#delete all files in @files
foreach $file (@files){
print "Deleting $path/$file\n";
# print `rm $path/$file`;
}
#delete all subdirectories recursivly
foreach $subdir (@subdirs){
print "Subdirectory: $path/$subdir\n";
empty("$path/$subdir"
# print `rm $path/$subdir`;
}
}
 
				
		 
			 
 
		 
 
		 
 
		 
 
		 
 
		
 Facebook
Facebook Twitter
Twitter