I have one subroutine which is running for ithread. The job of this subroutine is to refresh terminal object created through Term::Screen. When all rows of the screen is filled up & new line is added the screen is getting drifted & the topmost line is displayed on screen multiple times while scroll up the screen. I am able to solve this problem following way:
1. Maximum number of number of rows the screen supported
2. Remembering the line which is printed in top-most line of the screen while crossing max row.
For that one complete hash need to be remembered for at least for 80 consecutive runs.
Sample code is here:
Hash outside the sub routine:
%hash = (); // for storing drift line
%printable_data = (); // some data are there
$terminal = new Term::Screen;
$screen_height = $terminal->row;
The thread subroutine:
sub refresher
{
$terminal->at(0,0);
$terminal->clreos();
foreach (keys %printable_data) {
$term->puts($_);
.
.
.
if ( $curser_position >= $screen_height )
{
$hash{$key} = $_;
}
}
}
If I use closure instead of global variable like %hash, will it reduce the performance? Or it will increase the performance as it is associated with ithread?
One more thing, Is my approach is right in order to stop the duplicate print on screen while scrolling?
Few more hashes may require to remember data while refreshing the screen in future.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|