in reply to Simple Blackjack progam help
First of all, please start your code with
use strict; use warning;
and declare your variables with my when you use them first.
Some others errors I noticed at first glance:
When you read in a line with $variable = <STDIN>, then the variables has a trailing newline character. Usually you don't need that, so remove it by calling chomp $variable.
if ($another == 'y')
== is for comparing numbers, but 'y' isn't a number. Instead use
my $another = <STDIN>; chomp $another; if ($another eq 'y') { ... }
next:
$draw1 = int &draw;
Your draw subroutine already calls int, there's no need to do it twice
sub draw { $draw = int rand(10); }
That returns an integer between 0 and 9, not between 1 and 10.
Please search a bit for debugging tips & tricks here on perlmonks, there a quite a few that could have caught many of these errors, and probably many other errors that still lurk in your code.
|
|---|