Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Simple Blackjack progam help

by moritz (Cardinal)
on Oct 13, 2012 at 17:48 UTC ( #998863=note: print w/replies, xml ) Need Help??

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') { ... }


$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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998863]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-02-19 00:41 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (257 votes). Check out past polls.