perlquestion
oldirtysingh
Hi ppl,
<p>Got a really weird problem, which comes and goes but is upsetting my perl output.</p>
Code snippet
<code>
sub cheat {
my $cheatfile = "/home/cheatsheets/$prefix.txt";
open( INFO, $cheatfile );
@lines = <INFO>;
close(INFO);
foreach (@lines){
print $_;
}
}
</code>
##above stores and prints file contents to screen
<code>
my $counter = 0;
while($counter <= 1){
$session->exp->interact(\*STDIN,"\cA");
my $exit = qx(cat $showlog);
if ($exit =~ /exit|quit|logout|Inactivity/){
print colored("logfile:$showlog\n",'yellow');
die;
++$counter;
}
&cheat;
$session->exp->send("\r\n");
}
</code>
<p>
#the above hands session to user..... and loops until it finds an exit|logout or quit in the logfile then quits<br>
#in the meantime whilst in interact mode the user can press cntrl + a and it prints the files contents by calling the subroutine.
</p>
This all works fine... however the output of the file changes
<p>
correct output
</p>
<code>
networks>
adslc -s -s 1________________________line status [card mode]
adslc -s -e 1________________________line errors [card mode]
networks>
</code>
<p>
incorrect output
</p>
<code>
networks>
adslc -s -s 1________________________line status [card mode]
adslc -s -e 1________________________line errors [card mode]
networks>
</code>
<p>
i can press cntrl + a any number of times and randomly the output will distort from the normal format like above.
</p>
<p>
Anyone know a possible cause? Tried all kinds of workarounds and come to the conclusion that anytime a "\n" is used in the loop, this distortion occurs every so often. The next line in the file prints at the end of the previous line but on a newline, if that makes sense :s
</p>
<code>
i.e.
line1
line2
line3
</code>
<p>
Would be very greatful for the help
</p>