I hate having to launch "less" or "more" when it seems like perl is up to the task.

So on a program I am currently writing I hacked together this teensy tiny little sub, which does the trick quite nicely. I suppose if somebody asks for it, I will hack in a more less-like 'readchar' functionality. it hardly seems necessary for what it does.

note: it requires a use vars qw() or other (such as our) form of global variable.

sub page { foreach (@_) { print "$_"; $ln++; if ($ln+1 == $=) { print "--more--"; chop (my $i=<>); $ln = 0 } } }
invocation:

{ page "foo bar baz bletch"; page @an_array_of_text; page $foo; # or if you must... my $buf = sprintf ("%.5d", $real); page $buf; }

Replies are listed 'Best First'.
Re: Minuscule Pager Sub.
by petral (Curate) on Mar 20, 2001 at 00:02 UTC
    I'm guessing you're chopping $i, in case you should add some more functionality. :)

    p
A reply falls below the community's threshold of quality. You may see it by logging in.