Solved

replace a string in a perl array.

Posted on 2006-10-24
3
2,201 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now