This is my first perl program. It is a skiing program. I wrote it in basic decades ago. Thought it would be a fun way to get aquainted with perl and introduce my son to programing.

The first part randomly fills the screen with Ts that represent trees. Then it goes into a loop that puts a V on the screen that represents the skier.

This is where I am having a problem. When the j key is pressed I want the V to move to the left. When the k key is pressed I want the V to move to the right. Instead it breaks out of the loop and the text stops scrolling.

How can I fix this so the V moves and the scrolling continues. Code below.

#!/usr/bin/perl use Win32::Console::ANSI; use Term::ANSIScreen qw/:color :cursor :screen/; use Term::ReadKey; ReadMode('noecho'); cls; #fill the screen with Ts $y = 1; while ($y < 100) { $col = int(rand(80)); printf ("%${col}s\n", T); $y = $y + 1; } $wait = 1; $skierx = 40; $skiery = 0; $y = $y + 5; while (1 < 2) { while (not defined ($key = ReadKey(-1))) { # No key pressed $col = int(rand(79)); $y = $y + 1; locate $y,$col; print "T\n"; $skiery = $y - 50; locate $skiery,$skierx; print "V"; #locate $y,1; print "$skiery $skierx $key"; select(undef, undef, undef, $wait); #pauses here $wait = $wait - .003; } # here when key pressed if ($key == "j") {$skierx = $skierx - 1;} if ($key == "k") {$skierx = $skierx + 1;} if ($key == "x") {exit;} }

In reply to newbie learning perl by mkesling

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.