Hi All, That was helpful! Thank you very much. The problem was that I was using a DOS file and I think the chomp was probably able to remove one of the newlines and not a \r. The interesting thing is "chomp"ing twice did not seem to help either. However, 1 "chomp" and 1 "chop" did. Just thought I'd share that with you all.
Thanks again! Nupur -----Original Message----- From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED] Sent: Friday, June 03, 2005 6:59 PM To: Nupur Pande Cc: beginners@perl.org Subject: Re: question about appending spaces to each line of a file On Jun 3, Nupur Pande said: > I want to read each line from a file, chomp off the newline character, > append 6694 spaces to the end of each line and then output the line into > a new file. > > while ($line = <Filehandle1>) { > chomp $line; > $lengthofLine = length($line); Ok so far... > for ($i = 0; $i < 6694; $i++) { > $line = $line.' '; > } YECH! Didn't you think to yourself "there has to be a better way to write this code?" $line .= (" " x 6694); That appends 6,694 spaces to the end of $line. > print $lengthofLine." ".$line."\n"; > > print outfile1 "$lengthofLine"."$line"."\n"; Those can be: print "$lengthofLine $line\n"; print outfile1 "$lengthofLine$line\n"; > } #endwhile > However, the output file looks very strange. The first line doesn't have > any appended spaces whatsoever and from the second line onwards, the > spaces are appended at the beginning of the line instead of the end. That doesn't sound right... you *are* chomp()ing the string, so the newline should disappear. Perhaps you also have \r (carriage return) at the end of each line too? -- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ % -- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>