package Text::Break; $VERSION = 0.01; :) sub break { my($text, $how_many) = @_; $how_many ||= 24; my $total = @$text; ## Anon sub $printer is a closure and has access ## to the $text array reference. Yes, there's really ## no point to having an anon sub here; I may as ## well just write the print statement inline. Oh well. my $printer = sub { my($start, $how_many) = @_; print @{$text}[$start..$start+$how_many-1]; }; my $printed = 0; ## Separate the printing from the input, etc. PAGER: while ($printed <= $total) { $printed = 0 unless $printed >= 0; $printer->($printed, $how_many); $printed += $how_many; print $printed >= $total ? "--No More--" : "--More--"; my $in = ; if ($in =~ /^b/i) { $printed -= $how_many * 2; } elsif ($in =~ /^x/i || $in =~ /^q/i) { last PAGER; } } }