Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2211
  • Last Modified:

replace a string in a perl array.

hello experts. does anyone know how I can replace strings in my array into a different string? example @array = ("A H")
I would like to replace the a with ace and h with hearts. thanks.
0
micromarch
Asked:
micromarch
  • 2
1 Solution
 
ozoCommented:
s/A/ace/,s/H/hearts/ for @array;
0
 
HonorGodCommented:
ozo, you are something else...  no wonder you have so many answered questions & points. :-)
0
 
ozoCommented:
#anticipating another question:
my %tr=(
H => "hearts",
S => "spades",
D => "diamonds",
C => "clubs",
A => "ace",
2 => "two",
3 => "three",
4 => "four",
10 => "ten",
J => "jack",
K => "king",
Q => "queen",
);
s/(\d+|\w)/$tr{uc $1}/g for @array;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now