Can anyone tell me why I ran out of memory when I ran this code. It is a simple directory search that starts off where you are and searched to the end of that directory. However, when I ran it, it gave me an illegal operation error and said that I was out of memory. I believe the problem is in the @ARGV statement in the first sub function. Any clues?
#!/usr/bin/perl -ws
use strict;
use Cwd;
my $mode;
&op;
&scandir("C:/mydocu~1");
sub op
{
if (defined (@ARGV) $ARGV[0]=~/-all/)
{
$mode="all";
}else{
$mode="";
}
}
sub scandir
{
my ($workdir) = &scandir;
my ($startdir) = &cwd;
chdir($workdir) || die "Unable to change to $workdir: $!\n";
opendir(DIR, ".") || die "Unable to open $workdir: $!\n";
my @files = readdir(DIR) || die "Unable to read $workdir: $!\n";
closedir(DIR) || die "Unable to close $workdir: $!\n";
foreach my $file (@files)
{
next if ($file eq ".");
next if ($file eq "..");
if ($mode eq "all")
{
if (-d $file)
{
&scandir;
next;
}
if (-f $file)
{
if($file =~ m/\.\d+\w+\-\d+\wm$/i ||
$file =~ m/\.log$/i)
{
unlink($file) || warn "Unable to delete: $file: $!\n";
}else{
print "No files to delete!\n";
}
}
}
elsif ($mode eq "")
{
if(-d $file)
{
&scandir;
next;
}
if (-f $file)
{
if($file =~ m/\.\d+\w+\-\d+\wm$/i)
{
unlink($file) || warn "Unable to delete: $workdir\/$fi
+le: $!\n";
}else{
print "No files to delete!\n";
}
}
}
chdir($startdir) || die "Unable to change to $startdir: $!\n";
}
}
&scandir(".");
Thanks in advance
curtisb -- "Be careful what you wish for, it may come back and bit you in the ass!"