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
|