Perl Help

Scootin159

Diamond Member
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 (&quot;Checking $path\n&quot;);

#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 &quot;..&quot;){
next; #skip parent dir
} elsif ($line eq &quot;.&quot;){
next; #skip current dir
} elsif ($a eq &quot;/&quot;){
push(@subdirs,$line);
} else {
if ($a eq &quot;@&quot;){
push(@files,$line);
} else {
push(@files,$line.$a);
}
}
}


#delete all files in @files
foreach $file (@files){
print &quot;Deleting $path/$file\n&quot;;
# print `rm $path/$file`;
}

#delete all subdirectories recursivly
foreach $subdir (@subdirs){
print &quot;Subdirectory: $path/$subdir\n&quot;;
empty(&quot;$path/$subdir&quot;);
# print `rm $path/$subdir`;
}
}
 

Scootin159

Diamond Member
Apr 17, 2001
3,650
0
76
Originally posted by: Xiety
Just FYI, wrong forum :)

Belongs to Software-Applications, Programming

yeah, but I was hoping for a reply in the next couple hours...

I'll xpost it there anyways...