Thanks for your quick response.
> while (<iFH>) {
> chomp;
> s/\n/\r\n/g; # Need to see if this works. I think, it should work.
> print oFH;
> }
>> close oFH;
>> close iFH;
>> $files[$i] = "$tmpfile$i";
>Don't know why you are doing this ??
I was going to read thru @files later and attach each file named to an
email, so I had to replace the original filename with the new converted
filename.
This is why I didn't think 'foreach' would work. OR perhaps I'm just
remembering now that the $row in 'foreach $row (@array)' is a reference to
$array[current]?
"Shishir K. Singh" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
-----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.
>I must misunderstand the use of the file test, but I'm not getting any help
>from "Programming Perl" or the man pages.
>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.
> for (my $i=0; $i<=scalar(@files);$i++){
I assume that the values in @files are properly filled in. If so, define my
$i outside the for expression for proper scoping.
Also you don't need to give scalar on @files
my $i = 0;
for ($i = 0; $i < @files ;$i++){
or
for ($i = 0; $i <= $#files ;$i++){
> if (-f $files[$i] && -T $files[$i]) {
This should now work.
> open (iFH, "<$files[$i]") or die ("$progname: Can't open
infile ->>$files[$i]\n"); # input file
You can use $! to spit out the error message.
open (iFH, "<$files[$i]") or die ("$progname: LINE: ",__LINE__, " !$
$files[$i]\n");
> open (oFH, ">$tmpfile$i") or die ("$progname: Can't open
tmpfile ->$tmpfile$i\n");
> while (defined(my $txtline = <iFH>)){
> chomp($txtline);
> $txtline =~ s/\n/\r\n/g;
> print oFH $txtline;
> }
The above can be rewritten as
while (<iFH>) {
chomp;
s/\n/\r\n/g; # Need to see if this works. I think, it should work.
print oFH;
}
> close oFH;
> close iFH;
> $files[$i] = "$tmpfile$i";
Don't know why you are doing this ??
> }
> }
Consider using foreach instead of for
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]