Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Answer: How do I reverse a string or the words in a string?

by pokemonk (Scribe)
on Jul 21, 2001 at 04:16 UTC ( #98599=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > How do I reverse a string or the words in a string? - Answer contributed by pokemonk

#lie about myself $str='i am a sexy bastard'; #split the words @words=split ' ', $str; #revers 'em @words=reverse @words; #join 'em $reversestr=join ' ', @words;

Edit by tye to include wine's suggestion

Replies are listed 'Best First'.
Re: Answer: How do I reverse a string or the words in a string?
by wine (Scribe) on Jul 21, 2001 at 14:19 UTC

    You probably want to joint them with a space:

    $reversestr=join ' ', @words;

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2017-02-19 17:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (293 votes). Check out past polls.