Not at all. Here's something simple that I had in mind when I suggested Term::Cap. Don't worry about the use v5.14, it's only needed for 'say', and it replaces use strict;. Just use something recent you have available. Unfortunately, I'm not able to test this under Windows, which I suppose is the OS you're working on, but still, it may be of some use. Best luck with your project.

#!/usr/bin/perl use POSIX; use Term::Cap; use v5.14; # init the term my $termios = new POSIX::Termios; $termios->getattr; my $ospeed = $termios->getospeed; my $tc = Tgetent Term::Cap { TERM => undef, OSPEED => $ospeed }; # require the following capabilities $tc->Trequire(qw/cl cd ce cm co li/); # clear screen, clear to end of line, clear to end of screen sub cl_scr { $tc->Tputs('cl', 1, *STDOUT) } sub cl_line { $tc->Tputs('ce', 1, *STDOUT) } sub cl_end { $tc->Tputs('cd', 1, *STDOUT) } # move the cursor sub gotoxy { my($x, $y) = @_; $tc->Tgoto('cm', $x, $y, *STDOUT); } sub pline { my ($line_no, $string) = @_; gotoxy(0,$line_no); cl_line; print $string; } my @log = map { " > " } (0..9); # redraw the log sub flush_log { my $i = 0; for my $logline (@log) { pline ($i, $logline); $i++; } pline ($i, "=================================================="); gotoxy(0,++$i); cl_end; } # print line to log sub plog { my $line = shift; shift @log; push @log, " > $line"; flush_log; } my $correct = 42; my $number; my $choice; flush_log; do { print "What is the correct number: "; chomp($number = <STDIN>); if ($number == $correct) { plog "Game result: WIN"; say "Good answer. Play again? (y/n)"; chomp($choice = <STDIN>); } else { plog "Game result: LOSE"; say "Bad answer. Play again? (y/n)"; chomp($choice = <STDIN>); } } while ($choice eq 'y');

Relevant info from termcap manual:

`cl' String of commands to clear the entire screen and position the cur +sor at the upper left corner. `cd' String of commands to clear the line the cursor is on, and all the lines below it, down to the bottom of the screen. This command string should be used only with the cursor in column +zero. `ce' String of commands to clear from the cursor to the end of the curr +ent line. `cm' String of commands to position the cursor at line l, column c. Both parameters are origin-zero, and are defined relative to the s +creen, not relative to display memory. `co' Numeric value, the width of the screen in character positions. `li' Numeric value, the height of the screen in lines.

What it should look like:

> > > > > > > Game result: LOSE > Game result: WIN > Game result: LOSE > Game result: LOSE ================================================== Bad answer. Play again? (y/n) y What is the correct number:

- Luke


In reply to Re^3: Pure Perl Split Screen by blindluke
in thread Pure Perl Split Screen by PilotinControl

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.