PERL BEGINNERS 46 STILL NEED UNLINK HELP GOD HELP ME
Date: Fri, 8 Aug 2003 20:01:42 -0400 (EDT)

Subject: Still need unlink help!! God help me.
From: perlwannabe@no-spam (Perlwannabe)

Still having problem with unlink. My original problem began with deleting files from a list. I seem to have fixed the problem reading the list but the unlink does not work.

Here is the test script that I am working from:

my $file = 'listitems.txt';
open my $fh, $file or die "Cannot open $file: $!";
while($Line = <$fh>) {
chomp($Line);
my $del = "*$Line*.*";
my $complete = "c:/testdir/$del";
unlink glob $complete or die "unlink failed: $!";
}

A sample of the contents of the 'listitems.txt' file is:

item997
item996
item999
item983

The directory c:/testdir/ contains many files, but I want to delete the files with any *item###*.* from the directory. So if the directory has 3000 files I want to delete every file that has item997 in it.

So file "testitem997document.txt" will be deleted as well as "real1tem997file.doc" as well as "killitem983.txt.doc".

The sample script I posted aboveis returning the following error:
unlink failed: at testscript.pl line 7, <$fh> line 1.

Working in Windows XP and ActivePerl 5.8.0. BTW...this is perl.beginners so be kind and understanding. :-)


Subject: Re: Still need unlink help!! God help me.
Date: Fri, 8 Aug 2003 21:39:22 -0400

From: bobx@no-spam (Bob X)
"Perlwannabe" <perlwannabe@no-spam> wrote in message news:YW50aWdvbmU=.7af697ee56fdcc9b2afb1e89f798017d@no-spam > Still having problem with unlink. My original problem began with deleting > files from a list. I seem to have fixed the problem reading the list but > the unlink does not work.
>
> Here is the test script that I am working from:
>
> my $file = 'listitems.txt';
> open my $fh, $file or die "Cannot open $file: $!";
> while($Line = <$fh>) {
> chomp($Line);
> my $del = "*$Line*.*";
> my $complete = "c:/testdir/$del";
> unlink glob $complete or die "unlink failed: $!";
> }
>

Can you post more of the script? As it stands $fh is nothing.

Normally I would open a filehandle like so:

my $file = 'listitems.txt';
open(FH, "<" . $file) || die "Failed to open $file: $!";