I'm trying to write a module that allows you to put an array through a routine that will pause it when the screen's full of text. If you type in a b before conitinuing it will go back a screen. If you type a x it will stop printing. However, I'm having a bit of trouble. I can only get it to go back once, and once you type in b you have to hit enter twice. I just started Perl a couple months ago and this is my first time with a module. Here's the code:
package Text::Break;
$VERSION = 1.1;
sub break() {
local ($extra, $num, $extra2, $extra4, @text, $status);
local $text = \@_;
shift @$text;
$text3 = @$text;
if ($text3 =~ /,\s/) {
($text, $num) = split ", ", @$text, 2;
} else { $num = 24 }
local $counter = 1;
$status = "yes";
$extra2 = 0;
&printer;
sub printer() {
undef(@text);
while ($extra2 <= $#$text) {
$text[$extra4] = $$text[$extra2];
$extra2++;
$extra4++;
}
$extra4 = 0;
foreach $line (@text) {
if ($counter%24==0 && $status == "yes" && $counter != 0){
print "--more--";
$extra = <STDIN>;
if ($extra =~ /^[bB]/ && $counter != 24) {
$extra2 = $counter - 48;
undef($status);
goto &printer;
goto LAST;
} elsif ($extra =~ /^[xX]/) {
goto LAST;
}
}
print $line;
$counter++;
$status = "yes";
}
}
LAST: if($extra) {
}
1;
}
thanx for any help, I hope this is easy to understand the module's Text::Break, to call it use the break method. The code should be self-explanitory.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.