This is my first perl program. I wanted to learn perl and introduce my 9 year old to programming with it. He likes games. This is a skiing game. It runs in a windows 7 command prompt shell. It works until I use warnings. Then I get "Use of uninitialized value in numeric eq (==) at line 59" if I change to = the warning goes away but the $skierx stops working in the prior line and the V wont print. I think string vs number problem but don't know how to fix.
here are the problem lines locate $skiery,$skierx; print "V"; if ($skierx == $xloc[$skiery]) {print "CRASH!!!"; exit;} <code/> <p> below is the entire thing <p> <code> #!/usr/bin/perl use strict; #use warnings; use Win32::Console::ANSI; use Term::ANSIScreen qw/:color :cursor :screen/; use Term::ReadKey; ReadMode('noecho'); cls; my $col = 0; my $skierx = 40; my $skiery = 0; my $score = 0; my $key = 0; my $wait = .3; my $y = 1; #fill the screen with Ts while ($y < 100) { $col = int(rand(80)); printf ("%${col}s\n", "T"); $y = $y + 1; } $wait = 1; my $skierx = 40; my $skiery = 0; my @xloc = (); $y = $y + 5; locate $y,1; print " ------------------------- Ready Set GO! --------------- +----------"; while (1 < 2) { while (not defined ($key = ReadKey(-1))) { # here when no key pressed # place a T and save X location in array, position in array = Y $col = int(rand(80)); $y = $y + 1; $xloc[$y] = $col; locate $y,$col; print "T\n"; $skiery = $y - 50; # place V locate $skiery,$skierx; print "V"; if ($skierx == $xloc[$skiery]) {print "CRASH!!!"; exit;} #score if ($skiery < 105) {locate $skiery,1; print "PRACTICE X $skierx +Y $skiery";} if ($skiery > 105) {$score = $score + 1;locate $skiery,1; print +"$score";} # keep speeding up, reducing pause time select(undef, undef, undef, $wait); #pauses here #$wait = $wait - .005; if ($score eq 50) {$wait = .25;} if ($score eq 100) {$wait = .2;} if ($score eq 150) {$wait = .15;} if ($score eq 200) {$wait = .1;} } # here when key pressed if ($key eq ",") {$skierx = $skierx - 1;} if ($key eq ".") {$skierx = $skierx + 1;} if ($key eq "x") {exit;} } END{ ReadMode('restore'); }
In reply to more perl newbie misery by mkesling
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |