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

x
?
Solved

How to reverse a string using perl

Posted on 2011-09-28
2
Medium Priority
?
303 Views
Last Modified: 2012-05-12
Hello, I would like to reverse "All the best" to "best the All". I know if I split it on space on put in a array then I can print the reverse array. But here I would like to get it done without using array. is there a way?

I am doing kind of this but not sure what is missing to get the output as "best the All"

perl -le '$string = "All the best"; print scalar reverse $string'
tseb eht llA

Open in new window

0
Comment
Question by:beer9
  • 2
2 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 36715272
perl -le '$_="All the best";print join" ",reverse split'
0
 
LVL 85

Expert Comment

by:ozo
ID: 36715419
or
perl -le '($string = "All the best") =~ s/(\S+)/reverse $1/eg;print scalar reverse $string'
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.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

783 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