Please omit the using perl part in your questions. Did you notice that this site is all about using perl?
Here the $d1 is not fetching the folders and sub folders filename .
So you are doing something wrong. Let's revise your code. First, your variable naming is poor. They don't tell what's meant, they could also be $blorfldyick or $foo or $captain_morgan or $jonathan_swift.
sub DelTask{
my ($w1) = shift;
my $m1 = $w1 . '/*';
my @d1 = glob $m1;
The first argument to this function is a directory. So you should check whether it really is a directory, and bail out if it isn't:
unless (-d $w1)
{
warn "argument to DelTask is not a directory.\n";
return;
}
You don't need the temporary variable $m1, since you can construct a string on the fly:
my @d1 = glob "$w1/*";
Then you loop over @d1 (again, poor variable naming) using the temporary variable $f which should be $file. Agree?
foreach my $f (@d1)
{
my $d1 = basename($f);
Where in your posted code is use File::Basename? or did you roll your own basename() function? Where is that in your code? See, omissions like this one make it hard to understand your question and providing an answer. You assume that we might tell what's meant, but to assume makes an ass from u and me.
if ($d1 =~ /^white*/)
Where did you read that the string white refers to whitespace? Read perlre. Seriously, read perlre. You did? skip the rest of this paragraph. You didn't yet? I'm going to swear and insult you: You fool of a monk, goddamn, for god's sake and our souls peace, GO READ perlre!
Done? Ok, then you already know that you want this instead:
if ($d1 =~ /^\s+/)
In the next part you are trying to fix errors at the wrong place.
{
my $f1 = $f . '*';
print $f1;
unlink glob $f1;
unlink $f;
}
}
}
glob ought to have given you the filenames already, so there is no need to invoke it again. But, again, you are not checking whether the thing in $f is a file or a directory. Unlinking a directory containing files is a very bad idea.
update: If you want to remove recursively, this is the place to invoke DelTask($f)
Fix these errors, and then your call
DelTask($o_dir);
will yield the desired effect, or tell you what went wrong.
Happy coding!
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
|