Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (10)
As of 2024-04-18 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found