Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Too much text

by elusion (Curate)
on Aug 02, 2000 at 06:39 UTC ( [id://25648]=perlquestion: print w/replies, xml ) Need Help??

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

If I have a perl script printing a large amount of data onto the screen how do I make it so that it fills the screen and then pausess? or better yet, be able to scroll? Also, I'd like to be able to 'abort' the process after a screen if I like. Thanx for you help.

- p u n k k i d
"Reality is merely an illusion, albeit a very persistent one." -Albert Einstein

Replies are listed 'Best First'.
RE: Too much text
by chip (Curate) on Aug 02, 2000 at 10:11 UTC
    Unless you've landed in a very inhospitable environment--like, say, Windows--you should be able to take advantage of the native tools. For example:
    local $SIG{PIPE} = 'IGNORE'; open PAGER, '|'.($ENV{PAGER} || 'less') or die "Can't spawn pager: $!\n"; while (something) { print PAGER something_else; } close PAGER;

    The (temporary) assignment to $SIG{PIPE} keeps your program from dying if the pager quits early. If you're concerned about wasting time generating useless data, you may want to add this refinement:

    select PAGER; $| = 1; while (something) { print something_else or last; }

    Remember, tool use is one of the things that make us human. :-)

    UPDATE:Thanks to agoth for the bug fix. And yes, tye, I know that Windows has a "more" command. But it's so hostile that I never use it. There is a Windows port of "less", anyway.

        -- Chip Salzenberg, Free-Floating Agent of Chaos

      But

      open PAGER, ($ENV{PAGER} || 'less') . '|' or die "blah $!";

      Doesn't open a pipe to the pager, least not on my system? (main::PAGER only opened for input), Am I missing something? But thanks for leading me to:

      open PAGER, ('|' . $ENV{PAGER}) or die "blah $!";

        Correct. And that should be

        $ENV{PAGER} || 'more'

        so that it works on Windows (contrary to the original proposers claim) and on many other systems that may not have 'less' installed.

Re: Too much text
by jlp (Friar) on Aug 02, 2000 at 06:42 UTC
    It sounds like you may find the Term::* modules helpful. They can help you control terminal output.
Re: Too much text
by slurp (Initiate) on Aug 02, 2000 at 15:00 UTC
    You may assign a subroutine to $SIG{INT} that aborts the process after a certain screen. This subroutine will be rn each time ^c is pressed
    $SIG{INT} = sub { print "recieved SIGINT. Help!!\n"; }
    -- slurp

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://25648]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found