So as a practice for learning perl, I decided to write a simple game of blackjack. I'm using an array for the card values. I want to be able to include jack, king and queen cards in the players card list however I also want to be able to use these cards for adding to 21. First thought I tried to use a variable however this doesn't seem to work.
The array: @cards = (1,2,3,4,5,6,7,8,9,10,$ace ='ace',$jack ='jack', $queen ='queen', $king ='king'); #NOTE: Ace is 11 or 1
sub PrintPlayersCards
{
$playerTotal = 0;
print "PLAYERS CARDS:@playerCurCards\n";
@cards[$jack] = 10;
@cards[$queen] = 10;
@cards[$king] = 10;
grep {$playerTotal += $_} @playerCurCards;
print "Your total is :$playerTotal\n";
@cards[$king] = "King";
@cards[$queen] = "queen";
@cards[$jack] = "jack";
}
@playerCurCards is an array which stores the players cards. EG: 3 from the start and king from a hit etc.
$ace = 'ace'and the other similar will not translate to what you are doing. Why not instead of $ace put 'ace' or 11 ?