On Fri, 8 Aug 2003 22:16:38 -0400 (EDT), perlwannabe wrote:
> I tried both the suggested methods without success. But, I mightuv found a
> problem.  I tried all of these methods with no success and looked at the
> input file "listitems.txt" and found something interesting when using a
> hexeditor.  Each line ends with 0D0A, so in a hex editor the previous file
> looks like:
okay... in ascii the hex of 0d0a works out to character #13 and #10 
which works out to CR and LF.

CRLF is the normal Carriage Return Linefeed that is used to separate 
lines on windows.

It seems that everybody here pointed you into the right direction... 
but there seems to be something else wrong than the provided code (or 
your code for that matter). It seems that the data you use is the 
problem.

To really find out what the problem is... you need to learn how to 
debug your code. A starting point would be:

        perldoc perldebtut<Return>
or
        perldoc perldebug<Return>

you should type that on the dos/command prompt in windows.

Add the following lines to your program under the perl location line:

        use warnings;   
        use diagnostics;
        use strict;

It will check automatically for stractural errors that are often made 
and will give you (hopefully) meaningful error/warning messages.

Another thing to do is to print everything to the screen.

You define a variable? Print it.
You use a variable? Print it before it's use and after it's use.

BTW. Write at first in PSEUDOCODE and than translate it into perl. (I 
will add comments instead)

E.g.:
#!/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";
        # unlink a list of files that are returned by the globing command or 
fail
        my $deleted_files = unlink (glob $complete) or die "unlink failed: $!";
        # print out the number of the 'unlinked' files
        print $deleted_files."\n";
}

So... following this you are opening a file and for each line that the 
file contains you are trying to unlink all files returned by 'glob 
$complete'.

What you should do, if you have still problems after working through 
perldebtut and perldebug, is the following:

Write a test program with the same care you use for real programs. Add 
PSEUDO CODE or COMMENTS of what you want the code to do. Add debug 
helps (print to screen, use Data::Dumper for comples structures)...

thanks
/oliver/



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

Reply via email to