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);

In reply to Re: Breaking Text by chromatic
in thread Breaking Text by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.