|
Guys I am learning perl right now and I have been attempting to write a script that starts in the current working directory and find files. Below is the code ..... where did I go wrong?
Any help would be great
_______________________________________________________________________________________________
#!/usr/bin/perl -s
#use warnings;
#use strict;
my $mydir = "/index.html";
my @file = ("foo.bar", "bar.foo", "oof.rab", "rab.oof", "rab.foo", "oof.bar", "foo.bared" );
use Cwd;
sub ScanDirectory{
## The directory we are on now
my ($workdir) = shift;
## Directory place holder
my ($startdir) = $mydir;
## Go to the starting directory
chdir($workdir) or die "Unable to enter dir $workdir:$!\n";
## Open the directory to read contense
opendir(DIR, ".") or die "Unable to open $workdir:$!\n";
## Put everything you find into the array @names
my @names = readdir(DIR) or die "Unable to read $workdir:$!\n";
## close the directory
closedir(DIR);
## Go through the file names found
foreach my $name (@names){
## Do not look at "." or ".."
next if ($name eq ".");
next if ($name eq "..");
## If it is a directory ignore it
if (-d $name){
&ScanDirectory($name);
next;
}
## If the file name is the same as one we are looking for and the "-r" switch is given at the command line Delete the file.
if ($name eq "$file1") {
if (defined $r){
unlink($name) or die "Unable to delete $name:$!\n";
print "found one in $workdir!\n";
}
}
}
## Open the next directory
chdir($startdir) or
die "Unable to change to dir $startdir:$!\n";
}
&ScanDirectory ($cwd);
|
|
|
|
|
|
|
|