> -----Original Message-----
> From: Thomas 'Gakk' Summers [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 25, 2002 8:34 AM
> To: [EMAIL PROTECTED]
> Subject: File testing
> 
> 
> Warning: Perl Novice Alert!
> 
> I'm trying to:
> 1. read in a list of files,
> 2. test for text,
> 3. convert the text files from '\n' unix to '\r\n' dos
> 4. write them to a temporary location.
> 
> The code below produces an error: 'Use of uninitialized value 
> in -f at...'
> in line 2.

That's a warning, not an error. Your script still runs. Frequently that
warning is innocuous, but here it points to a minor flaw in your code.

> 
> I must misunderstand the use of the file test, but I'm not 
> getting any help
> from "Programming Perl" or the man pages.

No, your file test is OK.

> Please help?
> 
> p.s.  My method of converting is flawed as well, but I 
> haven't tried to fix
> it yet.  Please feel free to comment on how better to do that.
> p.p.s. I suspect that numerous other bugs are here, but I 
> haven't been able
> to test the 'for loop' either.
> 
> *******************************8
>   for (my $i=0; $i<=scalar(@files);$i++){
                    ^^
This should be just < (less than).

If @files contains 10 elements, then you are allowing $i to range 0 to 10.
But there is no $files[10]. $files[9] is the last entry.

Also, you don't technically need scalar() here, since the boolean comparison
evaluates @files in scalar context anyway.

A more idiomatic way to write this is:

   for my $i (0 .. @files) {

I'll let others comment on the rest of the script....

[snip]

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

Reply via email to