Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to reverse a string using perl

Posted on 2011-09-28
2
276 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 84

Accepted Solution

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

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Perl for loop for 2000 ms 7 105
Perl DBI Transactions Using Custom Module 7 48
Union rows in array that have common elements 2 101
Call Shell Script from Perl Script 6 134
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

838 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