The EOLN character is not being stripped out, so you're getting it before your quote. chomp it to remove it. Here's my version:
#!/usr/bin/perl -w use strict; open INFILE, "accounts.txt" or die "Can't open INFILE: $!"; open OUTFILE, ">nospace.txt" or die "Can't open OUTFILE: $!"; while (<INFILE>) { chomp; ($line=~/ /) ? (print OUTFILE "\"$_\"\n") : (print OUTFILE "$_\n"); } close INFILE; close OUTFILE; Pete On Thu, 6 Mar 2003, Carrara, Greg wrote: > Hello, > I'm trying to write a script that reads a file line by line and if the line > contains a space it puts quotation marks around it and writes it to another > file. I mostly have this working except that in the case of the lines that > contain the space it puts the quotation mark at the beginning of the next > line. My guess is that > print OUTFILE ($line); > also feeds a CR. Is there a way around this? > thanks, > gc > > > > > unless (open(INFILE, "accounts.txt")) { > > die ("Cannot open input file accounts.txt.\n"); > } > > unless (open(OUTFILE, ">nospace.txt")) { > > die ("Cannot open output file nospace.txt.\n"); > } > > $line = <INFILE>; > > while ($line ne "") { > > if ($line =~ / +/) { > print OUTFILE ('"'); > print OUTFILE ($line); > print OUTFILE ('"'); > } > else { > print OUTFILE ($line); > } > > $line = <INFILE>; > > } > } > > -- http://emerson.wss.yale.edu/perl Pete Emerson WSS AM&T Yale University -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]