On Sat, 9 Aug 2003 00:22:09 -0400 (EDT), perlwannabe wrote:
> I did indeed comment every single
> variable, but deleted it from my sample script for simplicity.  I have
> been wrestling with this problem for a while.  I did run your code and got
> the following error:
> 
> C:\testdir>perl testfile.pl
> listitems.txt
> item997
> *item997*.*
> c:/testdir/*item997*.*
> Uncaught exception from user code:
>         unlink failed:  at testfile.pl line 27, <FH> line 1.
great... ;) I love to remote debug other peoples script (yup, thqt was 
irony).

--- script starts
#!/usr/bin/perl

use warnings;
use diagnostics;
use strict;

# Declaration and initialization of $file
my $file = 'listitems.txt';
print $file."\n";

# Open $file with a filehandle of FH, die if problems arise
open FH, $file or die "Cannot open $file: $!\n";
# Go through the while loop as long as FH returns lines
while(<FH>) 
{
        # print line that is returned from FH
        print $_;
        # Remove trailing return from line
        chomp;
        # Set $del to the globing pattern
        my $del = "*".$_."*.*";
        print $del."\n";
        # Set $complete to the path and append the globbing pattern in $del
        my $complete = "c:/testdir/$del";
        print $complete."\n";
        # find a list of all files fitting $complete
        my @filenames = glob $complete;
        # print out each filename and delete them one by one... and hopefully 
finding the error
        foreach (@filenames)
        {
                print "Deleting ".$_."... ";
                my $result = unlink ($_) or die "has failed. Error: $!\n";
                print "was successful!\n" if $result;
        }
}
---script ends

Btw. everything was okay in the previous script until the 'unlink' 
command was reached. Did you look into permission problems? Are you 
trying to delete files that are maybe locked by IIS?
 
> You mention a "perl location line"  what is that?
'#!/usr/bin/perl' is the perl location line, because it tells the shell 
were it can find the program that it needs to run the script (on unix 
that is).

I hope that this script finds the culprit for you.

thanks
/oliver/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to