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.


In reply to Will closure increase performance thread processing subroutine? by elf_firein

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.