If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > last character prints on a new line

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-22-05, 15:40
Alexxx12 Alexxx12 is offline
Registered User
 
Join Date: Sep 2002
Location: NJ
Posts: 139
last character prints on a new line

Windxp
perl 5.8.7

I wrote a sample code to add a letter at the end of each line. The problem is that the letter
is added on the next line even though it is part of the line above. how do I make sure it prints
at the end of the line and not at the begining of the next?


Lxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
Lxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
Wxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
Oxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
Hxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx
Exxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxx
OU

Code:
$out="c:/perl/files/output.txt";
open OUT, ">>$out" or die "Cannot open $out for append :$!";
&printfile;
close OUT;

sub printfile {

	open(INFILE,  "C:/CONV/R/demo.err")   or die "Can't open file: $!";
		
	$cnt2=0;

	while (<INFILE>) { 
		
		$_=~ tr/A-Z/a-z/;

		@array=split//,$_;
		$x="";
		$cnt=0;
		
		@message=split//,"HELLO WORLD. HOW ARE YOU?";
				
		foreach $i (@array) {
				
			if ($i eq @array[-1]) {
				
				$x = $x.$i.@message[$cnt2];
				$cnt2 = $cnt2 + 1;

			} else {
	
				$x = $x.$i;
			}

		}

		print OUT $x.@message[$cnt2] if @array[0] ne "*" and @message[$cnt2] ne "";
	}

	close INFILE;
}
Reply With Quote
  #2 (permalink)  
Old 12-23-05, 12:59
senza_nome senza_nome is offline
Registered User
 
Join Date: Jun 2004
Location: Nowhere Near You
Posts: 89
You need to chomp the line.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On