Solved

replace a string in a perl array.

Posted on 2006-10-24
3
2,205 Views
Last Modified: 2012-08-13
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
Comment
Question by:micromarch
  • 2
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17797968
s/A/ace/,s/H/hearts/ for @array;
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17798290
ozo, you are something else...  no wonder you have so many answered questions & points. :-)
0
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 17798684
#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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question