in reply to Breaking Text

Not to be outdone, here's my version. It *is* Object Oriented, because I like blessing things besides hashes. I'll also give an example on how it's used. Note that this does clobber the original array. It's easier to do it without clobbering, and it easy to add a line to fix it.
#!/usr/bin/perl -w package Text::Break; use strict; use vars qw( $VERSION ); $VERSION = 1.2; # hey, why not? sub new { my $class = shift; my $lines = shift || 24; # a nice default my $self = \$lines; bless($self, $class); return $self; } sub break { my $self = shift; printer($$self, shift); } sub printer() { my $num = shift; my $text_ref = shift; my $status = 1; my @old = (); my $back = 0; my $counter = 0; while (@$text_ref && $status) { foreach my $line (splice @{ $text_ref }, 0, $num) { print $line; # can add \n here if needed $counter++; push @old, $line; } print "-- More --"; my $cont = <STDIN>; if ($cont =~ /^[Bb]/) { $back++; my $num_back = $num * $back; $num_back = $num_back > $counter ? $counter : $num_back; unshift @$text_ref, splice(@old, -$num_back, $num_back); $counter -= $num_back; } elsif ($cont =~ /^[Xx]/) { $status = 0; last; } else { $back--; } } # optional: put back what we've paged # unshift (@$text_ref, @old) if (@old); } 1;
Strictly speaking, $status isn't necessary, but if you want to add better error handling, you may need it. Here's how to call it:
#!/usr/bin/perl -w use strict; use Text::Break; die "Need a file!\n" unless (@ARGV); my $tb = Text::Break->new(20); my @arr = <>; $tb->break(\@arr);