downer has asked for the wisdom of the Perl Monks concerning the following question:

I'm sure many of you are familiar with the linux utility less. I use it frequently. It is like more, but opens up a 'window' in your terminal where you can look at the data, which closes when you are done, not leaving a trace in your terminal. I would like to have a perl program output data in the same way. while the program is running, it fills up it's section of the terminal, and when you quit, there is no trace that the output was ever there. I hope this makes sense! i dont know what this is even called. Can some monk point me in the right direction or give me some hints on how to do this? ~downer

Replies are listed 'Best First'.
Re: "Less" perl output
by BrowserUk (Patriarch) on Sep 12, 2008 at 01:45 UTC
Re: "Less" perl output
by atcroft (Abbot) on Sep 12, 2008 at 01:41 UTC

    According to an item in the less FAQ, it appears to use the termcap libraries for screen handling. There are at least one or two modules, including Term::Cap, that appear to interface that library.

    Alternately, you might also be able to use another screen-handling module (such as the Curses module) to manipulate the output as you desire.

    HTH.

Re: "Less" perl output
by Your Mother (Archbishop) on Sep 12, 2008 at 01:41 UTC

    I haven't messed with any of this stuff in about 8 years but suspect you'll find what you need in things like Term::Screen and Term::Cap. Search for "term" at search.cpan.org for more possibilities.

Re: "Less" perl output
by GrandFather (Saint) on Sep 12, 2008 at 01:07 UTC

    Tk, although that may be a little fraught using a terminal session under *nix (would work fine with Windows though).


    Perl reduces RSI - it saves typing
Re: "Less" perl output
by betterworld (Curate) on Sep 12, 2008 at 12:52 UTC

    What you are describing is the "alternate screen" feature that some terminal emulators have. The linux virtual console, for instance, doesn't have this feature.

    not leaving a trace in your terminal.

    Actually this is not 100% true. In xterm you can find "Show alternate screen" in the menu that opens when you hold down Ctrl-MiddleButton. Even after less has been quit, xterm still shows its display (of your secret files) in the alternate screen.

    Update: Regarding your question how you can do this: I think that ncurses (which "less" uses) does this by default when you initiate the screen, so you should be able to do this with the Curses module (as atcroft suggests).

Re: "Less" perl output
by zentara (Cardinal) on Sep 12, 2008 at 14:23 UTC
Re: "Less" perl output
by sasdrtx (Friar) on Sep 12, 2008 at 14:54 UTC
    When I use less on Solaris, it actually dumps everything into the terminal stream. So I think this is possibly related to the shell or OS.

    sas