Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

by YuckFoo (Abbot)
on Dec 13, 2006 at 18:42 UTC ( #589648=note: print w/ replies, xml ) Need Help??


in reply to Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)

#!/usr/local/bin/lua function reverseWords(str) list = {} for word in string.gfind(str, "(%w+)") do table.insert(list, 1, word) end return (table.concat(list, " ")) end print(reverseWords(" one two three four "))
or maybe
#!/usr/local/bin/lua function reverseWords(str) list = {} string.gsub(str, "(%w+)", function(word) table.insert(list, 1, word) end) return (table.concat(list, " ")) end print(reverseWords(" one two three four "))
YuckFoo


Comment on Re: Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://589648]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2014-04-17 04:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (439 votes), past polls