Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

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.


Comment on Re: Simple Blackjack progam help
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998863]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2015-07-02 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls