Link to home
Start Free TrialLog in
Avatar of beer9
beer9Flag for India

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or
perl -le '($string = "All the best") =~ s/(\S+)/reverse $1/eg;print scalar reverse $string'