Solved

replace a string in a perl array.

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 100
Visual xHarbour 1 77
Batch file output 20 78
Base1 Encode/Decode 3 39
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

744 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

10 Experts available now in Live!

Get 1:1 Help Now