Thomas 'Gakk' Summers wrote: > > 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. > > *******************************8 > for (my $i=0; $i<=scalar(@files);$i++){ > if (-f $files[$i] && -T $files[$i]) { > open (iFH, "<$files[$i]") or die ("$progname: Can't open infile -> > $files[ > $i]\n"); # input file > open (oFH, ">$tmpfile$i") or die ("$progname: Can't open tmpfile -> > $tmpfi > le$i\n"); > while (defined(my $txtline = <iFH>)){ > chomp($txtline); > $txtline =~ s/\n/\r\n/g; > print oFH $txtline; > } > close oFH; > close iFH; > $files[$i] = "$tmpfile$i"; > } > }
Something like this should work: @ARGV = grep -T, @files; my ( $oldfile, $/, $\ ) = ( '', "\012", "\015\012" ); while ( <> ) { if ( $oldfile ne $ARGV ) { open OUT, "> /some/temp/location/$ARGV" or die "Cannot write to /some/temp/location/$ARGV: $!"; $oldfile = $ARGV; } print OUT; } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]