I have a command-line script that generates output intermittently. It may display a few lines, run for a couple of minutes, display a couple hundred lines, run for a couple more minutes, etc. The user needs to be able to reliably review all of the output as it is generated.

I thought, "no problem, I'll just pipe it to the more command" to enable pagination, like so:

unless (open(MORE, " | more")) { die("ERROR! Cannot fork a process to \"more\" command\n"); } print MORE "whatever\n";

But there are several problems with this. The main one is that "more" initially will not display anything until it has a full page of text to display. Several minutes could pass with nothing appearing on the screen, even though it may have output to display. In fact, if the script has little output to display, it could be quite a few minutes until the script finishes and all of the output is finally displayed on one page.

I thought that there surely must be a command-line switch to tell "more" (or "less") not to buffer the first page, but if there is, I can't find it. I've tried various workarounds without success and I'm stumped.

Another annoying side-effect of "more" is that if the user happens to press the space bar one or more times before the "--More--" prompt has appeared, it buffers the keys and processes them later, potentially spewing several pages of output without the user noticing it. I thought that there surely must be a way of preventing this "type ahead" problem, but my search for a fix to this has been fruitless, as well.

So is there a simple way to implement reliable paging in Perl without these side-effects?


In reply to Simple Way to Paginate Output? by bobdog

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.