Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Displaying output page-by-page?

by Spidy (Chaplain)
on Nov 21, 2004 at 18:31 UTC ( [id://409393]=perlquestion: print w/replies, xml ) Need Help??

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

If any of you have ever read POD out of a file in activeperl, you will notice that it only displays a single page of output, and the words 'press any key for more', to 'scroll' the output down to the next page. Does anyone know how I would be able to add this sort of functionality to my program?


...Also, does anyone know how I could compile my code to an .exe, but still have it support DBM? I've tried Perl2Exe, and all it gave me was an error.

Thanks,
Spidy

Replies are listed 'Best First'.
Re: Displaying output page-by-page?
by Zaxo (Archbishop) on Nov 21, 2004 at 18:47 UTC

    Here's one way, open local(*STDOUT), '|-', $ENV{'PAGER'} or warn $!; If the PAGER environment variable is not set, that will just warn you and go on.

    After Compline,
    Zaxo

Re: Displaying output page-by-page?
by castaway (Parson) on Nov 21, 2004 at 18:52 UTC
    Assuming a console app, the answer to the first question is Term::ReadKey. No idea about the second, sorry.

    C.

Re: Displaying output page-by-page?
by Spidy (Chaplain) on Nov 21, 2004 at 19:31 UTC
    Is there any way that I could do it without installing another module? me and module installing don't play well together.
      You mention Activestate, so I don't know whether the above suggestion of checking $ENV{'PAGER'} will work under that (it being a unixy convention) but one way or another you should be able to use the DOS pager more. RTFM, but either you can redirect the text to more, or write a temporary file, then more \tmp\mytmpfile.txt with a system call.


      the hatter
Re: Displaying output page-by-page?
by zentara (Archbishop) on Nov 22, 2004 at 14:16 UTC
    There are alot of variations on this simple idea. Here is 1 way. Put 1 or more files in as arguments on the command line. I'm sure the experts can golf it down. :-)
    #!/usr/bin/perl if(! defined $ARGV[0]){print "Need a file(s)\n";exit;} foreach my $file (@ARGV){ open (FH,"< $file") or warn "$!\n"; while(<FH>){ for(1..25){ my $line; if( $line = readline FH ){ print $line }; } print "Hit Enter for more or Control-c to Quit\n"; my $input = (<STDIN>); } close FH; }

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-25 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found