Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

( #98599=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How do I reverse a string or the words in a string? 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

Comment on Answer: How do I reverse a string or the words in a string?
Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-09-02 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (26 votes), past polls