[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

How to reverse a string using perl

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
beer9
Asked:
beer9
  • 2
1 Solution
 
ozoCommented:
perl -le '$_="All the best";print join" ",reverse split'
0
 
ozoCommented:
or
perl -le '($string = "All the best") =~ s/(\S+)/reverse $1/eg;print scalar reverse $string'
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now