String Substitution

I have the below bit of code and I'm printing out the top five cards
use strict
use warnings

my @startingdeck = ("A H","2 H","3 H","4 H","5 H","6 H","7 H","8 H",
"9 H","10 H","J H","Q H","K H",
"A D","2 D","3 D","4 D","5 D","6 D","7 D","8 D",
"9 D","10 D","J D","Q D","K D",
"A C","2 C","3 C","4 C","5 C","6 C","7 C","8 C",
"9 C","10 C","J C","Q C","K C",
"A S","2 S","3 S","4 S","5 S","6 S","7 S","8 S",
"9 S","10 S","J S","Q S","K S");

my $i = 0; my @randomdeck;
while ($i < 5){
$randomdeck[$i] = shift(@startingdeck); $i++;
$randomdeck[$i] = pop(@startingdeck); $i++;
}

print "The top 5 cards are: ";

$i = 0;
while ($i < 5 ){
print "$randomdeck[$i]\n "; $i++;
}

I want to substitute Hearts for H, C for Clubs and so on.  I tried
doing so:

$i = 0;
while ($i < 5 ){
  if $randomdeck =~ /H/ {
    s/H/Hearts/
}

Unfortunately, that's not doing the substitution and I'm pretty new to perl and regex, anyone have thoughts?  
   
print "$randomdeck[$i]\n "; $i++;
}
bmcquillAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
s/H/Hearts/ for @randomdeck;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
Note that @randomdeck would contain
J S
in addition to the cards you are printing
0
tel2Commented:
ozo's answer looks like a good replacement for your:
    $i = 0;
    while ($i < 5 ){
      if $randomdeck =~ /H/ {
        s/H/Hearts/
    }

But there are a lot of issues with your code, including syntax errors, like missing ';' on the 'use strict' and 'use warnings' lines.  I suggest you remove such basic errors before posting your code.
0
tel2Commented:
Here's a tidier way to populate your startingdeck, in case you're interested:

my @startingdeck;
for my $suit ('H', 'D', 'C', 'S')
{
        for my $num (2..10, 'J', 'Q', 'K', 'A')
        { push @startingdeck, "$num $suit" }
}

But personally, I wouldn't have a space between the number and suit for each card, unless it was needed for some good reason.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.