mkesling has asked for the wisdom of the Perl Monks concerning the following question:

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'); }

Replies are listed 'Best First'.
Re: more perl newbie misery
by GrandFather (Saint) on Feb 21, 2015 at 01:24 UTC

    I'd guess the down votes you are getting are because of the commented out use warnings and maybe because you haven't applied due diligence in working out for yourself why you are getting warnings.

    Just changing stuff at random without understanding, or at least a plan, is not the way to fix programming issues with any confidence at all that you've fixed the root issue. It's often easy to fix symptoms, but as you have found, that often doesn't have much to do with the bigger problem.

    Anyway, don't worry too much about the down votes (if you were), but take them as a hint that you should think a little longer about "why?".

    Perl is the programming world's equivalent of English
Re: more perl newbie misery
by marinersk (Priest) on Feb 21, 2015 at 00:31 UTC

    I know you know this -- but you keep backing the truck over your own foot anyway, so it bears repeating:

    use strict;
    use warnings;

    And stop commenting them out. That only hurts you.

    Seriously. Just grind through what it's telling you, because -- and I know you know this -- that's how you're going to learn to do it better, and more automatically.

    The sooner the better.

    Like right now.

    You will like where you end up, despite the current pain. Trust me

Re: more perl newbie misery
by Anonymous Monk on Feb 21, 2015 at 00:46 UTC

    more perl newbie misery

    Step away from the computer, take a break, watch a movie, shower, lunch ... take a break

Re: more perl newbie misery
by mkesling (Initiate) on Feb 20, 2015 at 23:00 UTC

    Just noticed response from GrandFather on prior post. Working on it.