开发者

Perl - Full Screen Scrolling

Was wondering if there was a way to have output in perl via the command line be scrollable a "page at a time"; like less/more in *Nix. I found something clos开发者_C百科e in stackoverflow archives, but i don't think it will work for me.

I need to output to detect the screen size and know what "full screen" is, whether that is a small window, or truly a full-screen window, and be able to do this on small or large monitors.

Someone referenced the Perl module Term::Pager - maybe someone can assist with this. However, nowhere did I see anything such as "auto" or something to have the output know what a true full screen was. The reason being is due to the amount of output that the program will generate (due to design), I need a "paging" feature.

Code as of 12/4 9:45AM CST

open MORE, '|more' or die "unable to start pager";
    open my $fh, '<', $file or die "can't open <$file> for reading $!"; {
    local $/ = "TYPE:\n";
    while ( my $record = <$fh> ) {
        [ .. snip snip ...]

How would I go about doing this to another open statement?


just pipe the output to less or more:

open MORE, '|more' or die "unable to start pager";
print MORE "hello $_!\n" for 1..1000;


#!/usr/bin/env perl -CLA
use 5.010;
use utf8;
use strict;
use autodie;
use warnings qw< FATAL all >;
use open qw< IO :utf8 :std>;
use sigtrap qw< stack-trace normal-signals error-signals >;
END { close STDOUT }

if (-t STDOUT) {
    my $pager = $ENV{PAGER} || "less";
    open(STDOUT, "| $pager");
}

If you prefer to be infernally annoying like Python or Java:

use Carp;
$^W = 1;
local $SIG{__WARN__} = sub { confess "untrapped warning" };

That should win you friends in certain postmodernist snob-circles, but whether you value their esteem is not for me to say.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜