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;
}